From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Jelinek To: binutils@sourceware.cygnus.com Subject: [RFC] Adding --skip-mismatch option to ld Date: Thu, 01 Jul 1999 00:00:00 -0000 Message-id: <19990604171207.W949@mff.cuni.cz> X-SW-Source: 1999-q2/msg00117.html Hi! I'm trying to get elf32_sparc and elf64_sparc environments running on the same machine on Linux, but Solaris has apparently the same issues but different paths. Basically, elf64_sparc is incompatible architecture with elf32_sparc and I'd like to make things easier for people to link the right thing and not to crash on incompatible architectures for every link. The first hunk just sets the default search dirs for the elf64_sparc emulations, both when it is the default target and when the default is elf32_sparc. Solaris linker first tries paths ending with /lib/sparcv9 and for Linux I'd like to use paths ending with /lib64. Now Solaris linker apparently skips a library in the search path if it is for the wrong architecture (=emulation) which makes a lot of sense to me, that's why I wrote the second part of this patch. I've made it optional and not default because it differs from the standard library path searching, on the other side without this any compilation with some wrong arch library in the search path before the correct arch one would die in error. 1999-06-04 Jakub Jelinek * emulparams/elf64_sparc.sh: Set up default LIB_PATH for elf64_sparc on linux and solaris. * lexsup.c: Added new option --skip-mismatch. * ld.h: Declare variable for it. * ldmain.c (main): Initialize it. * ldfile.c (ldfile_open_file_search): Use it. * ld.texinfo: Document it. --- ./emulparams/elf64_sparc.sh.jj Thu Apr 22 10:15:45 1999 +++ ./emulparams/elf64_sparc.sh Fri Jun 4 15:54:28 1999 @@ -10,3 +10,31 @@ MACHINE= DATA_PLT= GENERATE_SHLIB_SCRIPT=yes NOP=0x01000000 +if [ "x${host}" = "x${target}" ] ; then + # Native + case "$target" in + sparc*-linux*) + SPARC_ELF64_SUFFIX=64 ;; + sparc*-solaris*) + SPARC_ELF64_SUFFIX=/sparcv9 ;; + esac +fi +if [ -n "${SPARC_ELF64_SUFFIX}" ]; then + LIB_PATH=/lib${SPARC_ELF64_SUFFIX}:/lib:/usr/lib${SPARC_ELF64_SUFFIX}:/usr/lib + if [ "x${DEFAULT_EMULATION}" = "x${EMULATION_NAME}" ] ; then + if [ -n "${NATIVE_LIB_DIRS}" ]; then + LIB_PATH=${LIB_PATH}:`echo ${NATIVE_LIB_DIRS} | sed 's_/lib\(\|/\)$_/lib'${SPARC_ELF64_SUFFIX}_` + fi + if [ "${libdir}" != /usr/lib -a "${libdir}" != /usr/lib${SPARC_ELF64_SUFFIX} ]; then + LIB_PATH=${LIB_PATH}:`echo ${libdir} | sed 's_/lib\(\|/\)$_/lib'${SPARC_ELF64_SUFFIX}_` + fi + if [ "${libdir}" != /usr/local/lib -a "${libdir}" != /usr/local/lib${SPARC_ELF64_SUFFIX} ]; then + LIB_PATH=${LIB_PATH}:/usr/local/lib${SPARC_ELF64_SUFFIX}:/usr/local/lib + fi + else + LIB_PATH=${LIB_PATH}:/usr/local/lib${SPARC_ELF64_SUFFIX}:/usr/local/lib + fi + if [ "x${DEFAULT_EMULATION}" = "xelf32_sparc" ]; then + COMPILE_IN=true + fi +fi --- ./lexsup.c.jj Thu Apr 22 10:15:35 1999 +++ ./lexsup.c Fri Jun 4 15:15:53 1999 @@ -120,6 +120,7 @@ int parsing_defsym = 0; #define OPTION_NO_CHECK_SECTIONS (OPTION_CHECK_SECTIONS + 1) #define OPTION_MPC860C0 (OPTION_NO_CHECK_SECTIONS + 1) #define OPTION_NO_UNDEFINED (OPTION_MPC860C0 + 1) +#define OPTION_SKIP_MISMATCH (OPTION_NO_UNDEFINED + 1) /* The long options. This structure is used for both the option parsing and the help text. */ @@ -313,6 +314,8 @@ static const struct ld_option ld_options '\0', NULL, N_("Create a shared library"), ONE_DASH }, { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */ '\0', NULL, NULL, ONE_DASH }, + { {"skip-mismatch", no_argument, NULL, OPTION_SKIP_MISMATCH}, + '\0', NULL, N_("Keep searching if mismatched input file is found in the path"), TWO_DASHES}, { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON}, '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES }, { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, @@ -799,6 +802,9 @@ parse_args (argc, argv) link_info.shared = true; else einfo (_("%P%F: -shared not supported\n")); + break; + case OPTION_SKIP_MISMATCH: + command_line.skip_mismatch = true; break; case 'h': /* Used on Solaris. */ case OPTION_SONAME: --- ./ldmain.c.jj Thu Apr 22 10:15:33 1999 +++ ./ldmain.c Fri Jun 4 15:14:36 1999 @@ -203,6 +203,7 @@ main (argc, argv) command_line.interpreter = NULL; command_line.rpath = NULL; command_line.warn_mismatch = true; + command_line.skip_mismatch = false; command_line.check_section_addresses = true; /* We initialize DEMANGLING based on the environment variable --- ./ld.h.jj Thu Apr 22 10:15:30 1999 +++ ./ld.h Fri Jun 4 15:12:55 1999 @@ -128,6 +128,10 @@ typedef struct /* If true (which is the default), warn about mismatched input files. */ boolean warn_mismatch; + + /* If true, keep searching if a library mismatching output is + found in the search path. */ + boolean skip_mismatch; /* Remove unreferenced sections? */ boolean gc_sections; --- ./ldfile.c.jj Thu Apr 22 10:15:32 1999 +++ ./ldfile.c Fri Jun 4 16:50:53 1999 @@ -177,8 +177,41 @@ ldfile_open_file_search (arch, entry, li if (ldfile_try_open_bfd (string, entry)) { - entry->filename = string; - return true; + bfd * arfile = NULL; + + if (! command_line.skip_mismatch) + { + entry->filename = string; + return true; + } + + if (bfd_check_format (entry->the_bfd, bfd_archive)) + { + /* We treat an archive as compatible if it empty + or has at least one compatible object. */ + arfile = bfd_openr_next_archived_file (entry->the_bfd, NULL); + + if (!arfile) + arfile = output_bfd; + else + while (arfile + && !(bfd_check_format (arfile, bfd_object) + && bfd_arch_get_compatible (arfile, output_bfd))) + arfile = bfd_openr_next_archived_file (entry->the_bfd, arfile); + } + else if (bfd_arch_get_compatible (entry->the_bfd, output_bfd)) + arfile = output_bfd; + + if (arfile) + { + entry->filename = string; + return true; + } + + info_msg (_("skipping %s because it has incompatible architecture\n"), string); + bfd_close(entry->the_bfd); + entry->the_bfd = NULL; + } free (string); --- ./ld.texinfo.jj Thu Apr 22 10:15:31 1999 +++ ./ld.texinfo Fri Jun 4 16:24:12 1999 @@ -1053,6 +1053,16 @@ and SunOS platforms. On SunOS, the link shared library if the @code{-e} option is not used and there are undefined symbols in the link. +@kindex --skip-mismatch +@item --skip-mismatch +If a library with incompatible architecture is found in the search path, +just skip it as it was not there and keep searching with the next search +path element. Normally, the first library found in the search path is +chosen, and if the architecture is incompatible, it will either not link +or might give unexpected results. An @code{ar} library is considered +incompatible if it is not empty and contains no object with architecture +compatible to the output architecture. + @item --sort-common @kindex --sort-common This option tells @code{ld} to sort the common symbols by size when it Cheers, Jakub ___________________________________________________________________ Jakub Jelinek | jj@sunsite.mff.cuni.cz | http://sunsite.mff.cuni.cz Administrator of SunSITE Czech Republic, MFF, Charles University ___________________________________________________________________ UltraLinux | http://ultra.linux.cz/ | http://ultra.penguin.cz/ Linux version 2.2.9 on a sparc64 machine (1343.49 BogoMips) ___________________________________________________________________