]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
hppa64: Improve compatibility with HP ld on HP-UX
authorJohn David Anglin <danglin@gcc.gnu.org>
Sun, 15 Mar 2026 18:12:58 +0000 (14:12 -0400)
committerJohn David Anglin <danglin@gcc.gnu.org>
Sun, 15 Mar 2026 18:12:58 +0000 (14:12 -0400)
Provided symbols are revised to match those provided by HP ld.
This fixes startup issues caused by defining __FPU_MODEL,
__libdl_jmp_tbl and __systab.

This change adds the emultempl/hppa64elf.em file.  We now always
link against /lib/pa20_64/milli.a on HP-UX.

HP-UX shared libraries have some unresolved symbols.  So, we also
need to ignore unresolved symbols in shared libraries.

We adjust TEXT_START_ADDR and SHLIB_TEXT_START_ADDR to match the
values used by HP ld.

The .data section is moved to the start of the data segment.

2026-03-15  John David Anglin  <danglin@gcc.gnu.org>

ld/ChangeLog:

* emulparams/elf64hppa.sh (TEXT_START_ADDR): Revise value to match
HP ld value.
(SHLIB_TEXT_START_ADDR): Likewise.
(EXTRA_EM_FILE): Define.
(OTHER_SYMBOLS): Revise to match symbols provided by HP ld.
* emultempl/hppa64elf.em: New file.
* scripttempl/elf64hppa.sc: Move .data to start of segment.

ld/emulparams/elf64hppa.sh
ld/emultempl/hppa64elf.em [new file with mode: 0644]
ld/scripttempl/elf64hppa.sc

index 5afe0e2714a62ed12dca1847e74a999638326a2b..9f185ee491f543c7da5fbf4ebe21483ca37cc79e 100644 (file)
@@ -2,16 +2,16 @@ SCRIPT_NAME=elf64hppa
 ELFSIZE=64
 OUTPUT_FORMAT="elf64-hppa"
 NO_REL_RELOCS=yes
-TEXT_START_ADDR=0x4000000000001000
+TEXT_START_ADDR=0x4000000000000000
 DATA_ADDR=0x8000000100000000
 TARGET_PAGE_SIZE=4096
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 LIB_PATH="=/usr/lib/pa20_64:=/opt/langtools/lib/pa20_64"
 
 # The HP dynamic linker actually requires you set the start of text and
-# data to some reasonable value.  Of course nobody knows what reasoanble
+# data to some reasonable value.  Of course nobody knows what reasonable
 # really is, so we just use the same values that HP's linker uses.
-SHLIB_TEXT_START_ADDR=0x4000000000001000
+SHLIB_TEXT_START_ADDR=0x4000000000000000
 SHLIB_DATA_ADDR=0x8000000100000000
 
 ARCH=hppa
@@ -20,6 +20,7 @@ NOP=0x08000240
 ENTRY="main"
 TEMPLATE_NAME=elf
 GENERATE_SHLIB_SCRIPT=yes
+EXTRA_EM_FILE=hppa64elf
 
 # We really want multiple .stub sections, one for each input .text section,
 # but for now this is good enough.
@@ -79,19 +80,21 @@ OTHER_SYMBOLS='
   PROVIDE (__TLS_INIT_SIZE = 0);
   PROVIDE (__TLS_INIT_START = 0);
   PROVIDE (__TLS_INIT_A = 0);
-  PROVIDE (__TLS_PREALLOC_DTV_A = 0);
-  PROVIDE (__SYSTEM_ID_D = 0);
-  PROVIDE (__TLS_SIZE_D = 0);
-  PROVIDE (__FPU_REVISION = 0);
-  PROVIDE (__FPU_MODEL = 0);
-  PROVIDE (__CPU_REVISION = 0);
-  PROVIDE (__CPU_KEYBITS_1 = 0);
-  PROVIDE (__LOAD_INFO = 0);
-  PROVIDE (__ARGC = 0);
-  PROVIDE (__ARGV = 0);
-  PROVIDE (__ENVP = 0);
-  PROVIDE (__libdl_jmp_tbl = 0);
-  PROVIDE (__systab = 0);'
+  PROVIDE (__TLS_PREALLOC_DTV_A = 0);'
+
+# These undefined symbols in libc are not provided by the HP linker.
+#  PROVIDE (__SYSTEM_ID_D = 0);
+#  PROVIDE (__TLS_SIZE_D = 0);
+#  PROVIDE (__FPU_REVISION = 0);
+#  PROVIDE (__FPU_MODEL = 0);
+#  PROVIDE (__CPU_REVISION = 0);
+#  PROVIDE (__CPU_KEYBITS_1 = 0);
+#  PROVIDE (__LOAD_INFO = 0);
+#  PROVIDE (__ARGC = 0);
+#  PROVIDE (__ARGV = 0);
+#  PROVIDE (__ENVP = 0);
+#  PROVIDE (__libdl_jmp_tbl = 0);
+#  PROVIDE (__systab = 0);
 
 # HPs use .dlt where systems use .got.  Sigh.
 OTHER_GOT_RELOC_SECTIONS="
diff --git a/ld/emultempl/hppa64elf.em b/ld/emultempl/hppa64elf.em
new file mode 100644 (file)
index 0000000..1aa0094
--- /dev/null
@@ -0,0 +1,56 @@
+# This shell script emits a C file. -*- C -*-
+#   Copyright (C) 1991-2026 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+# This file is sourced from elf.em, and defines extra hppa-elf
+# specific routines.
+#
+fragment <<EOF
+
+#include "ldctor.h"
+#include "elf64-hppa.h"
+
+/* Stop the linker merging .text sections on relocatable links,
+   add millicode library to the list of input files, and ignore
+   unresolved symbols in shared libraries.  */
+
+static void
+hppa64elf_after_parse (void)
+{
+  /* Stop the linker merging .text sections on relocatable links.  */
+  if (bfd_link_relocatable (&link_info))
+    lang_add_unique (".text");
+
+  /* We always need to link against milli.a on HP-UX.  */
+  lang_add_input_file ("/lib/pa20_64/milli.a",
+                      lang_input_file_is_file_enum,
+                      NULL);
+
+  /* HP-UX shared libraries have some unresolved symbols.  We need to
+     ignore unresolved symbols in shared libraries.  */
+  link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
+
+  ldelf_after_parse ();
+}
+EOF
+
+# Put these extra hppaelf routines in ld_${EMULATION_NAME}_emulation
+#
+LDEMUL_AFTER_PARSE=hppa64elf_after_parse
index d742675fb8c899bffcf9feb4c5ecf5202543c1f7..d093f88b8fb83370606b0ae0c17b4b0d7d631256 100644 (file)
@@ -428,6 +428,15 @@ cat <<EOF
   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
+  /* Put .data at start of segment.  */
+  .data         ${RELOCATING-0} :
+  {
+    ${RELOCATING+${DATA_START_SYMBOLS}}
+    *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
+    ${CONSTRUCTING+SORT(CONSTRUCTORS)}
+  }
+  .data1        ${RELOCATING-0} : { *(.data1) }
+
   /* Exception handling  */
   .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
   .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
@@ -459,13 +468,6 @@ cat <<EOF
 
   ${DATA_PLT+${PLT_BEFORE_GOT-${PLT}}}
 
-  .data         ${RELOCATING-0} :
-  {
-    ${RELOCATING+${DATA_START_SYMBOLS}}
-    *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
-    ${CONSTRUCTING+SORT(CONSTRUCTORS)}
-  }
-  .data1        ${RELOCATING-0} : { *(.data1) }
   ${WRITABLE_RODATA+${RODATA}}
   ${OTHER_READWRITE_SECTIONS}
   ${SMALL_DATA_CTOR+${RELOCATING+${CTOR}}}