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 <jerome.duval@gmail.com>
Diff
legacy/binutils/ld/emultempl/elf32.em | 7 +++++++
legacy/gcc/gcc/config/i386/haiku.h | 14 ++++++++++++--
2 files changed, 17 insertions(+), 4 deletions(-)
@@ -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
@@ -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 @@
#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}}"