From 81dcd49aad79ad58dfb63d1c776dee97b8e2c12b Mon Sep 17 00:00:00 2001 From: jmcmullan Date: Fri, 17 Aug 2012 02:41:47 +0000 Subject: [PATCH] collect-aros: Remove dependency on elfedit There is still a bug - the target's "strip" program is resetting the OS and ABI ELF fields I'll tackle that in a later patch. Signed-off-by: Jason S. McMullan git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@45584 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- configure | 183 ----------------------------------- configure.in | 7 -- tools/collect-aros/backend-bfd.c | 44 --------- tools/collect-aros/backend-generic.c | 17 ---- tools/collect-aros/backend.h | 1 - tools/collect-aros/collect-aros.c | 44 ++++++++- tools/collect-aros/env.h.in | 4 - 7 files changed, 41 insertions(+), 259 deletions(-) diff --git a/configure b/configure index 3bff17d05f..34fb3358d4 100755 --- a/configure +++ b/configure @@ -669,7 +669,6 @@ aros_target_nm aros_target_strip aros_target_objcopy aros_target_objdump -aros_target_elfedit aros_target_cc_path aros_target_cc_includes aros_target_ld @@ -733,7 +732,6 @@ aros_target_nix_ldflags aros_target_nostartup_ldflags aros_target_nostdinc_cflags aros_kernel_rescomp -orig_target_elfedit orig_target_objdump orig_target_objcopy orig_target_strip @@ -10634,7 +10632,6 @@ $as_echo "$target_tool_prefix" >&6; } orig_target_strip="${tmp_tool_prefix}strip" orig_target_objcopy="${tmp_tool_prefix}objcopy" orig_target_objdump="${tmp_tool_prefix}objdump" - orig_target_elfedit="${tmp_tool_prefix}elfedit" else # Determine whether AROS or ELF tools should be used if test "$aros_tool_prefix" = "none"; then @@ -12583,182 +12580,6 @@ fi if test "$orig_target_objdump" = ""; then as_fn_error $? "objdump is required to build AROS. Please install and run configure again." "$LINENO" 5 fi - -if test "${aros_tool_prefix}elfedit" = ""; then - if test "$cross_compiling" = "yes" ; then - # Extract the first word of "${target_tool_prefix}elfedit", so it can be a program name with args. -set dummy ${target_tool_prefix}elfedit; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path_orig_target_elfedit+:} false; then : - $as_echo_n "(cached) " >&6 -else - case $orig_target_elfedit in - [\\/]* | ?:[\\/]*) - ac_cv_path_orig_target_elfedit="$orig_target_elfedit" # Let the user override the test with a path. - ;; - *) - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_path_orig_target_elfedit="$as_dir/$ac_word$ac_exec_ext" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - - ;; -esac -fi -orig_target_elfedit=$ac_cv_path_orig_target_elfedit -if test -n "$orig_target_elfedit"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $orig_target_elfedit" >&5 -$as_echo "$orig_target_elfedit" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - - else - if test "$GCC" = "yes"; then - aros_gcc_elfedit=`$CC -print-prog-name=elfedit` - # Extract the first word of "`basename $aros_gcc_[elfedit]`", so it can be a program name with args. -set dummy `basename $aros_gcc_elfedit`; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path_orig_target_elfedit+:} false; then : - $as_echo_n "(cached) " >&6 -else - case $orig_target_elfedit in - [\\/]* | ?:[\\/]*) - ac_cv_path_orig_target_elfedit="$orig_target_elfedit" # Let the user override the test with a path. - ;; - *) - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in `dirname $aros_gcc_elfedit` -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_path_orig_target_elfedit="$as_dir/$ac_word$ac_exec_ext" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - - ;; -esac -fi -orig_target_elfedit=$ac_cv_path_orig_target_elfedit -if test -n "$orig_target_elfedit"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $orig_target_elfedit" >&5 -$as_echo "$orig_target_elfedit" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test "$orig_target_elfedit" = ""; then - # Extract the first word of "elfedit", so it can be a program name with args. -set dummy elfedit; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path_orig_target_elfedit+:} false; then : - $as_echo_n "(cached) " >&6 -else - case $orig_target_elfedit in - [\\/]* | ?:[\\/]*) - ac_cv_path_orig_target_elfedit="$orig_target_elfedit" # Let the user override the test with a path. - ;; - *) - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_path_orig_target_elfedit="$as_dir/$ac_word$ac_exec_ext" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - - ;; -esac -fi -orig_target_elfedit=$ac_cv_path_orig_target_elfedit -if test -n "$orig_target_elfedit"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $orig_target_elfedit" >&5 -$as_echo "$orig_target_elfedit" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi - fi -else - # Extract the first word of "${aros_tool_prefix}elfedit", so it can be a program name with args. -set dummy ${aros_tool_prefix}elfedit; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_path_orig_target_elfedit+:} false; then : - $as_echo_n "(cached) " >&6 -else - case $orig_target_elfedit in - [\\/]* | ?:[\\/]*) - ac_cv_path_orig_target_elfedit="$orig_target_elfedit" # Let the user override the test with a path. - ;; - *) - as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then - ac_cv_path_orig_target_elfedit="$as_dir/$ac_word$ac_exec_ext" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - - ;; -esac -fi -orig_target_elfedit=$ac_cv_path_orig_target_elfedit -if test -n "$orig_target_elfedit"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $orig_target_elfedit" >&5 -$as_echo "$orig_target_elfedit" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi - - if test "$orig_target_elfedit" = ""; then - as_fn_error $? "elfedit is required to build AROS. Please install and run configure again." "$LINENO" 5 -fi fi if test "$kernel_tool_prefix" = "none" ; then @@ -12952,7 +12773,6 @@ aros_target_ld="${prefix}ld" aros_target_ar="${prefix}ar $aros_target_ar_flags" aros_target_objcopy="${prefix}objcopy" aros_target_objdump="${prefix}objdump" -aros_target_elfedit="${prefix}elfedit" aros_target_ranlib="${prefix}ranlib $aros_target_ranlib_flags" aros_target_nm="${prefix}nm $aros_target_nm_flags" aros_target_strip="${prefix}strip" @@ -14423,7 +14243,6 @@ fi - # Delinting target compiler flags @@ -15260,7 +15079,6 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 orig_target_ar=${orig_target_ar} orig_target_ranlib=${orig_target_ranlib} orig_target_objdump=${orig_target_objdump} - orig_target_elfedit=${orig_target_elfedit} orig_target_objcopy=${orig_target_objcopy} orig_target_strip=${orig_target_strip} aros_kernel_ld=${aros_kernel_ld} @@ -15861,7 +15679,6 @@ $as_echo "$as_me: executing $ac_file commands" >&6;} ln -sf $orig_target_as$aros_host_exe_suffix ${prefix2}-as$aros_host_exe_suffix ln -sf $orig_target_nm$aros_host_exe_suffix ${prefix2}-nm$aros_host_exe_suffix ln -sf $orig_target_ar$aros_host_exe_suffix ${prefix2}-ar$aros_host_exe_suffix - ln -sf $orig_target_elfedit$aros_host_exe_suffix ${prefix2}-elfedit$aros_host_exe_suffix ln -sf $orig_target_ranlib$aros_host_exe_suffix ${prefix2}-ranlib$aros_host_exe_suffix ln -sf $orig_target_objcopy$aros_host_exe_suffix ${prefix2}-objcopy$aros_host_exe_suffix ln -sf $orig_target_objdump$aros_host_exe_suffix ${prefix2}-objdump$aros_host_exe_suffix diff --git a/configure.in b/configure.in index 19a2a083fa..9ba3699398 100644 --- a/configure.in +++ b/configure.in @@ -1718,7 +1718,6 @@ if test "$crosstools" = "yes"; then orig_target_strip="${tmp_tool_prefix}strip" orig_target_objcopy="${tmp_tool_prefix}objcopy" orig_target_objdump="${tmp_tool_prefix}objdump" - orig_target_elfedit="${tmp_tool_prefix}elfedit" else # Determine whether AROS or ELF tools should be used if test "$aros_tool_prefix" = "none"; then @@ -1752,8 +1751,6 @@ else AROS_REQUIRED(objcopy,$orig_target_objcopy) AROS_TOOL_TARGET(orig_target_objdump,objdump,${aros_tool_prefix}objdump) AROS_REQUIRED(objdump,$orig_target_objdump) - AROS_TOOL_TARGET(orig_target_elfedit,elfedit,${aros_tool_prefix}elfedit) - AROS_REQUIRED(elfedit,$orig_target_elfedit) fi if test "$kernel_tool_prefix" = "none" ; then @@ -1883,7 +1880,6 @@ aros_target_ld="${prefix}ld" aros_target_ar="${prefix}ar $aros_target_ar_flags" aros_target_objcopy="${prefix}objcopy" aros_target_objdump="${prefix}objdump" -aros_target_elfedit="${prefix}elfedit" aros_target_ranlib="${prefix}ranlib $aros_target_ranlib_flags" aros_target_nm="${prefix}nm $aros_target_nm_flags" aros_target_strip="${prefix}strip" @@ -2518,7 +2514,6 @@ AC_SUBST(aros_target_ld) AC_SUBST(aros_kernel_ld) AC_SUBST(aros_target_cc_includes) AC_SUBST(aros_target_cc_path) -AC_SUBST(aros_target_elfedit) AC_SUBST(aros_target_objdump) AC_SUBST(aros_target_objcopy) AC_SUBST(aros_target_strip) @@ -2682,7 +2677,6 @@ AC_CONFIG_COMMANDS([compiler_executable], ln -sf $orig_target_as$aros_host_exe_suffix ${prefix2}-as$aros_host_exe_suffix ln -sf $orig_target_nm$aros_host_exe_suffix ${prefix2}-nm$aros_host_exe_suffix ln -sf $orig_target_ar$aros_host_exe_suffix ${prefix2}-ar$aros_host_exe_suffix - ln -sf $orig_target_elfedit$aros_host_exe_suffix ${prefix2}-elfedit$aros_host_exe_suffix ln -sf $orig_target_ranlib$aros_host_exe_suffix ${prefix2}-ranlib$aros_host_exe_suffix ln -sf $orig_target_objcopy$aros_host_exe_suffix ${prefix2}-objcopy$aros_host_exe_suffix ln -sf $orig_target_objdump$aros_host_exe_suffix ${prefix2}-objdump$aros_host_exe_suffix @@ -2701,7 +2695,6 @@ AC_CONFIG_COMMANDS([compiler_executable], orig_target_ar=${orig_target_ar} orig_target_ranlib=${orig_target_ranlib} orig_target_objdump=${orig_target_objdump} - orig_target_elfedit=${orig_target_elfedit} orig_target_objcopy=${orig_target_objcopy} orig_target_strip=${orig_target_strip} aros_kernel_ld=${aros_kernel_ld} diff --git a/tools/collect-aros/backend-bfd.c b/tools/collect-aros/backend-bfd.c index 515eb44416..7116c5165b 100644 --- a/tools/collect-aros/backend-bfd.c +++ b/tools/collect-aros/backend-bfd.c @@ -8,35 +8,6 @@ #include "misc.h" #include "backend.h" -#ifndef ELFEDIT_NAME -#define ELFEDIT_NAME "elfedit" -#endif - -static FILE *my_popen(const char *command, const char *file) -{ - static char command_buf[MAXPATHLEN]; - - size_t command_len = strlen(command); - size_t file_len = strlen(file); - - FILE *pipe; - - if (file_len + command_len >= sizeof(command_buf)) - fatal("collect_sets()", strerror(ENAMETOOLONG)); - - memcpy(command_buf, command, command_len); - memcpy(command_buf + command_len, file, file_len + 1); - - set_compiler_path(); - - pipe = popen(command_buf, "r"); - if (pipe == NULL) - fatal(command_buf, strerror(errno)); - - return pipe; -} - - static void bfd_fatal(const char *msg) { fatal(msg, bfd_errmsg(bfd_get_error())); @@ -201,19 +172,4 @@ void collect_libs(const char *file, setnode **liblist_ptr) bfd_close(abfd); } -int set_os_and_abi(const char *file) -{ - FILE *pipe; - char buf[200]; - int cnt; - pipe = my_popen(ELFEDIT_NAME " --output-osabi=AROS ", file); - if (!pipe) - return 0; - - while ((cnt = fread(buf, 1, sizeof(buf), pipe)) != 0); - - pclose(pipe); - - return 1; -} diff --git a/tools/collect-aros/backend-generic.c b/tools/collect-aros/backend-generic.c index 8139f91d5a..011f32cf56 100644 --- a/tools/collect-aros/backend-generic.c +++ b/tools/collect-aros/backend-generic.c @@ -134,20 +134,3 @@ int check_and_print_undefined_symbols(const char *file) return there_are_undefined_syms; } - -int set_os_and_abi(const char *file) -{ - FILE *pipe; - char buf[200]; - int cnt; - - pipe = my_popen(ELFEDIT_NAME " --output-osabi=AROS ", file); - if (!pipe) - return 0; - - while ((cnt = fread(buf, 1, sizeof(buf), pipe)) != 0); - - pclose(pipe); - - return 1; -} diff --git a/tools/collect-aros/backend.h b/tools/collect-aros/backend.h index 09a0153a04..7f8b56edc8 100644 --- a/tools/collect-aros/backend.h +++ b/tools/collect-aros/backend.h @@ -6,6 +6,5 @@ extern int check_and_print_undefined_symbols(const char *file); extern void collect_sets(const char *file, setnode **setlist_ptr); extern void collect_libs(const char *file, setnode **liblist_ptr); -extern int set_os_and_abi(const char *file); #endif /* !_BACKEND_H_ */ diff --git a/tools/collect-aros/collect-aros.c b/tools/collect-aros/collect-aros.c index 0d72077b79..1c96693c46 100644 --- a/tools/collect-aros/collect-aros.c +++ b/tools/collect-aros/collect-aros.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #include "env.h" @@ -13,6 +15,12 @@ #define EXTRA_ARG_CNT 2 +#define EI_OSABI 7 +#define EI_ABIVERSION 8 + +#define ELFOSABI_AROS 15 + + static char *ldscriptname, *tempoutput, *ld_name, *strip_name; static FILE *ldscriptfile; @@ -28,6 +36,32 @@ static void exitfunc(void) remove(tempoutput); } +static int set_os_and_abi(const char *file) +{ + int f; + const unsigned char osabi = ELFOSABI_AROS; + const unsigned char abiversion = 1; + + /* Modify OS and ABI fields */ + + f = open(file, O_RDWR); + if (f >= 0) { + lseek(f, EI_OSABI, SEEK_SET); + if (write(f, &osabi, 1) == 1) { + lseek(f, EI_ABIVERSION, SEEK_SET); + if (write(f, &abiversion, 1) == 1) { + close(f); + return 1; + } + } + } + + perror(file); + if (f >= 0) + close(f); + return 0; +} + int main(int argc, char *argv[]) { int cnt, i; @@ -134,7 +168,7 @@ int main(int argc, char *argv[]) docommandvp(ld_name, ldargs); if (incremental == 1) - return EXIT_SUCCESS; + return set_os_and_abi(output) ? EXIT_SUCCESS : EXIT_FAILURE; collect_libs(tempoutput, &liblist); collect_sets(tempoutput, &setlist); @@ -165,7 +199,7 @@ int main(int argc, char *argv[]) tempoutput, "-T", ldscriptname, do_verbose, NULL); if (incremental != 0) - return EXIT_SUCCESS; + return set_os_and_abi(output) ? EXIT_SUCCESS : EXIT_FAILURE; if (!ignore_undefined_symbols && check_and_print_undefined_symbols(output)) { @@ -180,7 +214,11 @@ int main(int argc, char *argv[]) docommandlp(strip_name, strip_name, "--strip-unneeded", output, NULL); } - set_os_and_abi(output); + if (!set_os_and_abi(output)) + { + remove(output); + return EXIT_FAILURE; + } return 0; } diff --git a/tools/collect-aros/env.h.in b/tools/collect-aros/env.h.in index 1850bd4854..824650352c 100644 --- a/tools/collect-aros/env.h.in +++ b/tools/collect-aros/env.h.in @@ -16,21 +16,18 @@ #define STRIP_NAME "/Development/bin/strip" #define NM_NAME "/Development/bin/nm" #define OBJDUMP_NAME "/Development/bin/objdump" -#define ELFEDIT_NAME "/Development/bin/elfedit" #endif #ifdef _CROSS_ #define LD_NAME "@AROS_CROSSTOOLSDIR@/@aros_target_cpu@-aros-ld" #define STRIP_NAME "@AROS_CROSSTOOLSDIR@/@aros_target_cpu@-aros-strip" #define NM_NAME "@AROS_CROSSTOOLSDIR@/@aros_target_cpu@-aros-nm" #define OBJDUMP_NAME "@AROS_CROSSTOOLSDIR@/@aros_target_cpu@-aros-objdump" -#define ELFEDIT_NAME "@AROS_CROSSTOOLSDIR@/@aros_target_cpu@-aros-elfedit" #endif #ifdef _STANDALONE_ #define LD_NAME "@aros_target_cpu@-aros-ld" #define STRIP_NAME "@aros_target_cpu@-aros-strip" #define NM_NAME "@aros_target_cpu@-aros-nm" #define OBJDUMP_NAME "@aros_target_cpu@-aros-objdump" -#define ELFEDIT_NAME "@aros_target_cpu@-aros-elfedit" #endif #ifndef LD_NAME @@ -39,7 +36,6 @@ #define STRIP_NAME "@aros_target_strip@" #define NM_NAME "@aros_target_nm@" #define OBJDUMP_NAME "@aros_target_objdump@" -#define ELFEDIT_NAME "@aros_target_elfedit@" #endif #define TARGET_CPU_@aros_target_cpu@ -- 2.11.4.GIT