[binutils-gdb] hppa64: Improve compatibility with HP ld on HP-UX

John David Anglin via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7def0c077dc47cefa252f0c8df08f9b986b26306

commit 7def0c077dc47cefa252f0c8df08f9b986b26306
Author: John David Anglin <[email protected]>
Date:   Sun Mar 15 14:12:58 2026 -0400

    hppa64: Improve compatibility with HP ld on HP-UX
    
    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  <[email protected]>
    
    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.

Diff:
---
 ld/emulparams/elf64hppa.sh  | 35 +++++++++++++++-------------
 ld/emultempl/hppa64elf.em   | 56 +++++++++++++++++++++++++++++++++++++++++++++
 ld/scripttempl/elf64hppa.sc | 16 +++++++------
 3 files changed, 84 insertions(+), 23 deletions(-)

diff --git a/ld/emulparams/elf64hppa.sh b/ld/emulparams/elf64hppa.sh
index 5afe0e2714a..9f185ee491f 100644
--- a/ld/emulparams/elf64hppa.sh
+++ b/ld/emulparams/elf64hppa.sh
@@ -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
index 00000000000..1aa00944604
--- /dev/null
+++ b/ld/emultempl/hppa64elf.em
@@ -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
diff --git a/ld/scripttempl/elf64hppa.sc b/ld/scripttempl/elf64hppa.sc
index d742675fb8c..d093f88b8fb 100644
--- a/ld/scripttempl/elf64hppa.sc
+++ b/ld/scripttempl/elf64hppa.sc
@@ -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}}}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.