From 465fb4d4a7e2428f32530fe02ab0ef891f87d552 Mon Sep 17 00:00:00 2001 From: Simon South Date: Fri, 30 Oct 2015 13:28:32 -0400 Subject: [PATCH] gcc2: Allow the user to build non-PI executables This aligns legacy gcc with the changes to gcc4 committed in 4192115 and the two subsequent commits. It also disables legacy ld's default behaviour of recursively resolving shared-library dependencies at link time, preventing missing-library warnings during the build and aligning ld's behaviour with that of more recent versions. gcc2: * CPP_SPEC: Replace non-existent command-line options with valid equivalents. * CC1_SPEC: Remove non-existent "no-fpic" option; add "fno-pic" and "fno-PIC" as options that disable the generation of position-independent code; use "-fPIC" by default. * LINK_SPEC: Pass "-shared" to the linker only if it was passed to gcc; output position-independent executables by default, exporting all symbols to match the behaviour of "-shared"; when building a dynamically linked executable, do not recursively add shared libraries as dependencies but do allow unresolved symbols in them; specify "-Bsymbolic" only when building a shared library. * All: Wrap lines at 80 columns; use more compact notation where available. ld: * Do not recursively resolve shared-library dependencies when building an executable if the "--no-add-needed" and "--allow-shlib-undefined" options are in effect. This effectively backports binutils commits 8fbb09e and 4706eab. Signed-off-by: Jérôme Duval --- legacy/binutils/ld/emultempl/elf32.em | 7 +++++++ legacy/gcc/gcc/config/i386/haiku.h | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/legacy/binutils/ld/emultempl/elf32.em b/legacy/binutils/ld/emultempl/elf32.em index 1925979..f456e1a 100644 --- a/legacy/binutils/ld/emultempl/elf32.em +++ b/legacy/binutils/ld/emultempl/elf32.em @@ -891,6 +891,13 @@ && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0) continue; + /* Skip the lib if --no-add-needed and --allow-shlib-undefined + is in effect. */ + if (l->by != NULL + && link_info.unresolved_syms_in_shared_libs == RM_IGNORE + && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0) + continue; + /* If we've already seen this file, skip it. */ for (ll = needed; ll != l; ll = ll->next) if ((ll->by == NULL diff --git a/legacy/gcc/gcc/config/i386/haiku.h b/legacy/gcc/gcc/config/i386/haiku.h index 5321325..7c66036 100644 --- a/legacy/gcc/gcc/config/i386/haiku.h +++ b/legacy/gcc/gcc/config/i386/haiku.h @@ -163,14 +163,16 @@ -Asystem(haiku)" #undef CPP_SPEC -#define CPP_SPEC "%(cpp_cpu) %{!no-fPIC:%{!no-fpic:-D__PIC__ -D__pic__}}" +#define CPP_SPEC "%(cpp_cpu) %{!fno-pic:%{!fno-PIC:-D__PIC__ -D__pic__}}" /* Haiku uses lots of multichars, so don't warn about them unless the user explicitly asks for the warnings with -Wmultichar. Note that CC1_SPEC is used for both cc1 and cc1plus. */ #undef CC1_SPEC -#define CC1_SPEC "%{!no-fpic:%{!fPIC:-fpic}} %{!Wmultichar: -Wno-multichar} %(cc1_cpu) %{profile:-p}" +#define CC1_SPEC \ + "%{!fpic:%{!fPIC:%{!fno-pic:%{!fno-PIC:-fPIC}}}} \ + %{!Wmultichar: -Wno-multichar} %(cc1_cpu) %{profile:-p}" #undef CC1PLUS_SPEC #define CC1PLUS_SPEC "%{!Wctor-dtor-privacy:-Wno-ctor-dtor-privacy}" @@ -183,8 +185,12 @@ /* If ELF is the default format, we should not use /lib/elf. */ #undef LINK_SPEC -#define LINK_SPEC "%{!o*:-o %b} -m elf_i386_haiku %{!r:-shared} -Bsymbolic " \ - "%{nostart:-e 0} %{shared:-e 0} %{!shared: %{!nostart: --no-undefined}}" +#define LINK_SPEC \ + "%{!o*:-o %b} -m elf_i386_haiku \ + %{!shared:%{!r:%{!fno-pic:%{!fno-PIC:-pie --export-dynamic}} \ + %{!static:--no-add-needed --allow-shlib-undefined}}} \ + %{shared:-shared -Bsymbolic} %{nostart|shared:-e 0} \ + %{!nostart:%{!shared:--no-undefined}}" /* Provide start and end file specs appropriate to glibc. */ -- gitore 0.2.2