From 646868b77a1e4e616216d38961438f89c93f9aa9 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 27 Mar 2017 21:58:49 +0200 Subject: [PATCH] local syms --- nm-otool/Makefile | 6 +++--- nm-otool/includes/ft_nm_otool.h | 5 ++--- nm-otool/src/ft_nm.c | 7 ++++--- nm-otool/src/ft_otool.c | 4 ++-- nm-otool/src/symbol_filter.c | 3 ++- nm-otool/src/symbol_format.c | 18 ++++++------------ nm-otool/src/symbol_init.c | 12 ++++++------ nm-otool/src/symbol_sort.c | 4 ++-- nm-otool/tests/compile.sh | 1 - nm-otool/tests/stabs_define.c | 23 ----------------------- nm-otool/tests/test_facile | Bin 8432 -> 0 bytes nm-otool/tests/test_facile.c | 7 ------- nm-otool/tests/test_moins_facile | Bin 8480 -> 0 bytes nm-otool/tests/test_moins_facile.c | 9 --------- 14 files changed, 27 insertions(+), 72 deletions(-) delete mode 100644 nm-otool/tests/compile.sh delete mode 100644 nm-otool/tests/stabs_define.c delete mode 100755 nm-otool/tests/test_facile delete mode 100644 nm-otool/tests/test_facile.c delete mode 100755 nm-otool/tests/test_moins_facile delete mode 100644 nm-otool/tests/test_moins_facile.c diff --git a/nm-otool/Makefile b/nm-otool/Makefile index cc5e15fb..cea02344 100644 --- a/nm-otool/Makefile +++ b/nm-otool/Makefile @@ -6,7 +6,7 @@ # By: jhalford +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2017/02/19 03:29:38 by jhalford #+# #+# # -# Updated: 2017/03/26 15:37:30 by jhalford ### ########.fr # +# Updated: 2017/03/27 20:21:47 by jhalford ### ########.fr # # # # **************************************************************************** # @@ -104,14 +104,14 @@ clean: cleanlib: @make -C $(LIBFT_DIR) clean -fclean: clean +fclean: clean @$(RM) $(NAME) @printf "\r\e[38;5;196m❌ fclean $(NAME).\e[0m\e[K\n" fcleanlib: cleanlib @make -C $(LIBFT_DIR) fclean -re: fclean all +re: fclean relib all relib: fcleanlib $(LIBFT_LIB) diff --git a/nm-otool/includes/ft_nm_otool.h b/nm-otool/includes/ft_nm_otool.h index cdea18fd..f8630674 100644 --- a/nm-otool/includes/ft_nm_otool.h +++ b/nm-otool/includes/ft_nm_otool.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/20 14:36:10 by jhalford #+# #+# */ -/* Updated: 2017/03/26 19:12:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 20:59:15 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -108,12 +108,11 @@ void symbol_free(void *data, size_t size); int symbol_format(t_symbol *symbol); int symbol_format_full(t_symbol *symbol); int sym_format_undf(t_symbolmap map, t_symbol *symbol); -int sym_format_text(t_symbolmap map, t_symbol *symbol); int sym_format_stab(t_symbolmap map, t_symbol *symbol); void mach_64_parse(t_machodata *data); void dump_dysymtab(t_machodata *data, struct dysymtab_command *dysymtab); -void *hexdump(void *addr, unsigned int offset, unsigned int size); +void *hexdump(void *addr, unsigned int offset, unsigned int size); #endif diff --git a/nm-otool/src/ft_nm.c b/nm-otool/src/ft_nm.c index ab30aa87..56391a19 100644 --- a/nm-otool/src/ft_nm.c +++ b/nm-otool/src/ft_nm.c @@ -6,11 +6,12 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/19 03:09:12 by jhalford #+# #+# */ -/* Updated: 2017/03/26 19:12:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 20:59:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_nm_otool.h" +#define NM_USAGE "usage: nm [-a]" t_machodata *g_data = NULL; @@ -20,7 +21,7 @@ t_cliopts g_nm_opts[] = {'p', NULL, NM_NOSORT, 0, NULL, 0}, {'r', NULL, NM_RSORT, 0, NULL, 0}, - {0xff, "full", NM_FULL | NM_ALL, 0, NULL, 0}, + {0xff, "full", NM_FULL, 0, NULL, 0}, {'g', NULL, 0, 0, NULL, 0}, {'u', NULL, 0, 0, NULL, 0}, {'a', NULL, NM_ALL, 0, NULL, 0}, @@ -78,7 +79,7 @@ int main(int ac, char **av) if (cliopts_get(av, g_nm_opts, &data)) { ft_perror(); - ft_dprintf(2, "USAGE PLACEHOLDER\n"); + ft_dprintf(2, NM_USAGE); return (1); } i = data.av_data - av; diff --git a/nm-otool/src/ft_otool.c b/nm-otool/src/ft_otool.c index 9cbdcb03..10b870ed 100644 --- a/nm-otool/src/ft_otool.c +++ b/nm-otool/src/ft_otool.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/20 14:08:14 by jhalford #+# #+# */ -/* Updated: 2017/03/26 19:10:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 20:41:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,7 +47,7 @@ void otool(void *file) struct section_64 *sect; if (is_fat) - ft_printf("fat binary: not supported yet.\n"); + ft_printf("fat binary not supported yet\n"); else if (is_64) { sect = get_text_section(file); diff --git a/nm-otool/src/symbol_filter.c b/nm-otool/src/symbol_filter.c index 8bee61da..b5fa99f6 100644 --- a/nm-otool/src/symbol_filter.c +++ b/nm-otool/src/symbol_filter.c @@ -1,4 +1,5 @@ -/* ************************************************************************** */ +/* + ************************************************************************** */ /* */ /* ::: :::::::: */ /* symbol_filter.c :+: :+: :+: */ diff --git a/nm-otool/src/symbol_format.c b/nm-otool/src/symbol_format.c index 2e137513..1c37c718 100644 --- a/nm-otool/src/symbol_format.c +++ b/nm-otool/src/symbol_format.c @@ -4,7 +4,7 @@ t_symbolmap g_symbolmap[] = { {'U', sym_format_undf}, {'A', NULL}, - {'T', sym_format_text}, + {'T', NULL}, {'D', NULL}, {'B', NULL}, {'C', NULL}, @@ -20,15 +20,6 @@ int sym_format_undf(t_symbolmap map, t_symbol *symbol) return (0); } -int sym_format_text(t_symbolmap map, t_symbol *symbol) -{ - char c; - - c = symbol->nlist->n_type & N_EXT ? 'T' : 't'; - ft_printf("%016llx %c %s\n", symbol->nlist->n_value, map.c, symbol->string); - return (0); -} - int sym_format_stab(t_symbolmap map, t_symbol *symbol) { struct nlist_64 *stab; @@ -47,7 +38,8 @@ int symbol_format_full(t_symbol *symbol) symbol->pos, (symbol->nlist->n_type & N_STAB) >> 5, (symbol->nlist->n_type & N_PEXT) >> 4, - symbol->nlist->n_type & N_TYPE, symbol->nlist->n_type & N_EXT, + symbol->nlist->n_type & N_TYPE, + symbol->nlist->n_type & N_EXT, symbol->nlist->n_sect, symbol->section->sectname, symbol->nlist->n_desc, symbol->nlist->n_value, symbol->string); @@ -57,6 +49,7 @@ int symbol_format_full(t_symbol *symbol) int symbol_format(t_symbol *symbol) { t_symbolmap map; + char c; map = g_symbolmap[symbol->type]; @@ -64,8 +57,9 @@ int symbol_format(t_symbol *symbol) map.format(map, symbol); else { + c = symbol->nlist->n_type & N_EXT ? map.c : map.c + 32; ft_printf("%016llx %c %s\n", - symbol->nlist->n_value, map.c, symbol->string); + symbol->nlist->n_value, c, symbol->string); } return (0); } diff --git a/nm-otool/src/symbol_init.c b/nm-otool/src/symbol_init.c index 0848c421..94812851 100644 --- a/nm-otool/src/symbol_init.c +++ b/nm-otool/src/symbol_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/25 21:22:06 by jhalford #+# #+# */ -/* Updated: 2017/03/26 16:50:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 20:36:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,15 +40,15 @@ int symbol_set(t_symbol *symbol, t_machodata *data) symbol->type = SYM_COMMON; else if (type_mask == N_UNDF) symbol->type = SYM_UNDF; - else if (type_mask == N_SECT && ft_strcmp("__TEXT", symbol->section->segname) == 0) - symbol->type = SYM_TEXT; - else if (type_mask == N_SECT && ft_strcmp("__DATA", symbol->section->segname) == 0) - symbol->type = SYM_DATA; else if (type_mask == N_ABS) symbol->type = SYM_ABS; + else if (type_mask == N_SECT && ft_strcmp("__text", symbol->section->sectname) == 0) + symbol->type = SYM_TEXT; + else if (type_mask == N_SECT && ft_strcmp("__data", symbol->section->sectname) == 0) + symbol->type = SYM_DATA; else if (type_mask == N_INDR) symbol->type = SYM_INDR; else - symbol->type = SYM_UNDF; + symbol->type = SYM_OTHER; return (0); } diff --git a/nm-otool/src/symbol_sort.c b/nm-otool/src/symbol_sort.c index 872eb3d1..a85923dd 100644 --- a/nm-otool/src/symbol_sort.c +++ b/nm-otool/src/symbol_sort.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/26 15:03:55 by jhalford #+# #+# */ -/* Updated: 2017/03/26 19:20:49 by jhalford ### ########.fr */ +/* Created: 2017/03/27 20:33:02 by jhalford #+# #+# */ +/* Updated: 2017/03/27 20:33:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/nm-otool/tests/compile.sh b/nm-otool/tests/compile.sh deleted file mode 100644 index c5f0233b..00000000 --- a/nm-otool/tests/compile.sh +++ /dev/null @@ -1 +0,0 @@ -gcc -g3 stabs_define.c -w -o stabs_define diff --git a/nm-otool/tests/stabs_define.c b/nm-otool/tests/stabs_define.c deleted file mode 100644 index 505a50d8..00000000 --- a/nm-otool/tests/stabs_define.c +++ /dev/null @@ -1,23 +0,0 @@ -#define NONE 42 -#define TWO(a, b) (a + (a) + 2 * b) -#define ONE(c) (c + 19) - -main(int argc, char *argv[]) -{ - func(NONE, TWO(10, 11)); - func(NONE, ONE(23)); - -#undef ONE -#define ONE(c) (c + 23) - - func(NONE, ONE(-23)); - - return (0); -} - -int global; - -func(int arg1, int arg2) -{ - global = arg1 + arg2; -} diff --git a/nm-otool/tests/test_facile b/nm-otool/tests/test_facile deleted file mode 100755 index 58a820c341a8036ca8ac112d9e66477de2a9d170..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8432 zcmeHM&ubGw6rQwIOIz*sBL1qZ#fo}pE2sz}G}2&-MO&MK6?B@UTN6mqHoMXGRxE-! z6#6H46i*(DCq=~{7q1?@C>0buiiq+1W@nS#RJ{r^4_@B9d2haX^UW-5cHVyf@^gm} zu~s2gT7(eY&_``T+!Z!jLhOYmp;C^=FC?xdu3TnsRAN#0w;plcAyLXy;%X|IqQ+a% zKB0ZoCbns1hLoPOV#&zhZ?U-$LWV9f{lQbmD25e zX;$V-bMwlN?#G74V%74TQV0b<_J`nP+=F=Tg7SeyivoN0d?K+=+7?0;J>^Gi+vC&Hx6CbGO6pp|8cZg*y5}u*@U(jOXC<9B;s$f$fBjL&L({K*Rmv z_5-`=dC9xUWDgR{$pS@@LwP}cF}>EghtTc_iXS8u$?PW4V7MxO;0 zogGS#2R{2Ccn()Mj?ZCOI1kss7;BDoyutEfjkz)ZevB9f3GHFkl!k3>XIfH3L)0>WAd&XDhjO?ks9~nfSqqHh1FZ#OrF} zTlH0P^|^KZS*`yL17d8gcM&E&S?f>3uIJeK>0_-{OF6D*&!w~Zf`hIY^Z;X!u;sfn z-?dM|QmgvCn{ED|>B2}$jfNBbYoa>tBcIqt3GHFkl!k3>XFs1BL;^fMLKe zU>Nv+80hJ&{V*=CC(2@7l&zj&xlr+3w3Wmp?&DizF(;iRCtL9x z+;yj!eyEtvmqb55K(vbY2mS1NgWcURbyKLmFYH#n|E(hUmH}J;^w5WR*!N)-=rG$h SZiu(mAXN>1y<66!2LA$?p0^GF diff --git a/nm-otool/tests/test_facile.c b/nm-otool/tests/test_facile.c deleted file mode 100644 index aab6b7a6..00000000 --- a/nm-otool/tests/test_facile.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(void) -{ - puts("Test facile"); - return (0); -} diff --git a/nm-otool/tests/test_moins_facile b/nm-otool/tests/test_moins_facile deleted file mode 100755 index 54af825172c6b2483686ee86e26c92f9bc0a2943..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8480 zcmeHMO=uHA6rR|sp{+JODD{`6SWyrC5ye^%Qf)BBqWu#@kRfTdZD8|5ve5=SR7=4s zg&uqMss}ykRg@}T^w^VlQ4|zBiHI1#Z+5obq@}&fJa{|v&AfU0=9?Xuo%ind_rE)Z z2-OKOvrP!m3>Djjm=hLjVjnaPm2#->V(fZsB~%SJMD())Ln+5%*T$+%)c8ns zo6s1sF&w3|kkYlMUDiCQ^*4kG&|jDCC$86ZRn&`_Ae6G`mXgKQrdoe9+TRXs;bVV5 zSo`z)J%4h_cJg)sMz#L#X@C2*17h;ND(m7KFS>zDutM?H=q;wLS`HNsY?Ze7i2;!hWes@7EWh&t&v@wd> z_*%6;|63#8iZ^dx4Gvts6zd=G_k>l$8!*MvlVe=LdA4ESb}0jIE@4ZER$?udg}I^L zg))kgF|mKz^7hmUO2*L$9fAgh^QUe$k2hA${?ZP1qePczf_9dQg-$1(>`axN6forg zlyN-Gef+R(r1$QlxwFf+m!G{jf;Pr08XJ_J@G;vU$1q=xU>GnA7zPXjh5^HXVZbo36$4k} z^Pl3g-y-paa~ELyI`)Sn9-MxR=M(W|7mDtm^RZv^KjO2mA~#-E+V9gq3@#ihqv#v0 zw5L%nPO=v!IEcRo{dkTq~6izWY&3> zZ^Fok8VykWE1?>eU{BvTXB#mL7zPXjh5^HXVZbn87%&VN1`Gp+0mFb{;6GuYr7bed zskB6yoKwkgnM8gV$?M^QSQLdwOH}5OfOaQv1D;H>q^+u98#G+b>Fa8Vejt3zuRaIBcBHoV&>&gvZ|yT i&miXAhR(f4S+|g(T_2-VF(L)N7NbA8b< - -int une_globale = 40; - -int main(void) -{ - printf("La globale vaut: %d\n", une_globale); - return (0); -}