Ticket #12439: 0001-gcc2-Allow-the-user-to-build-non-PI-executables.patch

File 0001-gcc2-Allow-the-user-to-build-non-PI-executables.patch, 4.0 KB (added by simonsouth, 9 years ago)

gcc2: Allow the user to build non-PI executables

  • legacy/binutils/ld/emultempl/elf32.em

    From c06475954adc3e8752b56b0c2b1b2c4ef103a2d7 Mon Sep 17 00:00:00 2001
    From: Simon South <ssouth@simonsouth.com>
    Date: Fri, 30 Oct 2015 13:28:32 -0400
    Subject: [PATCH 1/2] 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.
    ---
     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 b gld${EMULATION_NAME}_after_open (void)  
    891891      && (bfd_elf_get_dyn_lib_class (l->by) & DYN_AS_NEEDED) != 0)
    892892    continue;
    893893
     894      /* Skip the lib if --no-add-needed and --allow-shlib-undefined
     895         is in effect.  */
     896      if (l->by != NULL
     897      && link_info.unresolved_syms_in_shared_libs == RM_IGNORE
     898      && (bfd_elf_get_dyn_lib_class (l->by) & DYN_NO_ADD_NEEDED) != 0)
     899    continue;
     900
    894901      /* If we've already seen this file, skip it.  */
    895902      for (ll = needed; ll != l; ll = ll->next)
    896903    if ((ll->by == NULL
  • legacy/gcc/gcc/config/i386/haiku.h

    diff --git a/legacy/gcc/gcc/config/i386/haiku.h b/legacy/gcc/gcc/config/i386/haiku.h
    index 5321325..7c66036 100644
    a b Boston, MA 02111-1307, USA. */  
    163163-Asystem(haiku)"
    164164
    165165#undef CPP_SPEC
    166 #define CPP_SPEC "%(cpp_cpu) %{!no-fPIC:%{!no-fpic:-D__PIC__ -D__pic__}}"
     166#define CPP_SPEC "%(cpp_cpu) %{!fno-pic:%{!fno-PIC:-D__PIC__ -D__pic__}}"
    167167
    168168/* Haiku uses lots of multichars, so don't warn about them unless the
    169169   user explicitly asks for the warnings with -Wmultichar.  Note that
    170170   CC1_SPEC is used for both cc1 and cc1plus. */
    171171
    172172#undef CC1_SPEC
    173 #define CC1_SPEC "%{!no-fpic:%{!fPIC:-fpic}} %{!Wmultichar: -Wno-multichar} %(cc1_cpu) %{profile:-p}"
     173#define CC1_SPEC \
     174  "%{!fpic:%{!fPIC:%{!fno-pic:%{!fno-PIC:-fPIC}}}} \
     175   %{!Wmultichar: -Wno-multichar} %(cc1_cpu) %{profile:-p}"
    174176
    175177#undef CC1PLUS_SPEC
    176178#define CC1PLUS_SPEC "%{!Wctor-dtor-privacy:-Wno-ctor-dtor-privacy}"
    Boston, MA 02111-1307, USA. */  
    183185/* If ELF is the default format, we should not use /lib/elf. */
    184186
    185187#undef  LINK_SPEC
    186 #define LINK_SPEC "%{!o*:-o %b} -m elf_i386_haiku %{!r:-shared} -Bsymbolic " \
    187     "%{nostart:-e 0} %{shared:-e 0} %{!shared: %{!nostart: --no-undefined}}"
     188#define LINK_SPEC \
     189  "%{!o*:-o %b} -m elf_i386_haiku \
     190   %{!shared:%{!r:%{!fno-pic:%{!fno-PIC:-pie --export-dynamic}} \
     191   %{!static:--no-add-needed --allow-shlib-undefined}}} \
     192   %{shared:-shared -Bsymbolic} %{nostart|shared:-e 0} \
     193   %{!nostart:%{!shared:--no-undefined}}"
    188194
    189195/* Provide start and end file specs appropriate to glibc.  */
    190196