diff options
author | Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> | 2025-08-19 12:52:41 +0200 |
---|---|---|
committer | Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> | 2025-08-19 12:52:41 +0200 |
commit | e067b9d0277039d04698099dc6f42d10c4a2bcb5 (patch) | |
tree | def064dae63d9aa51b3010928d835e58c14c6186 | |
parent | 09292f4ae2ccb46130652f6b310ee7a5227326d3 (diff) | |
download | binutils-e067b9d0277039d04698099dc6f42d10c4a2bcb5.zip binutils-e067b9d0277039d04698099dc6f42d10c4a2bcb5.tar.gz binutils-e067b9d0277039d04698099dc6f42d10c4a2bcb5.tar.bz2 |
bfd: Fix Solaris/x86 ELF_MAXPAGESIZE
I noticed that the alignment of the .text and .data sections on
Solaris/x86 doesn't match what /bin/ld does: gld uses the original i386
psABI default of 0x1000, while Solaris has moved to larger values as can
be seen both in the Oracle Solaris 11.4 Linkers and Libraries Guide,
ch. 15, Program Loading and Dynamic Linking, p. 15-6 and the system
headers (<sys/elf_{i386,amd64}.h>) that have
while the Solaris/SPARC values are already correct.
To fix this, on i386 it's sufficient to redefine ELF_MAXPAGESIZE. On
x86_64, unlike i386, ELF_COMMONPAGESIZE is hardcoded as 0x1000, the
default, so setting ELF_MAXPAGESIZE has no effect on ELF_P_ALIGN.
Setting ELF_COMMONPAGESIZE to ELF_MAXPAGESIZE, too, fixes that and
brings both target in sync. ELF_MACHINE_CODE is just set to the original
value again, so it's removed.
Tested on {i386,amd64}-pc-solaris2.11, {i686,x86_64}-pc-linux-gnu, and
amd64-pc-freebsd14.0.
2025-07-29 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
bfd:
* elf32-i386.c <elf32-i386-sol2> (ELF_MAXPAGESIZE): Redefine.
<elf32-iamcu> (ELF_MAXPAGESIZE): Restore previous value.
* elf64-x86-64.c (ELF_COMMONPAGESIZE): Define as ELF_MAXPAGESIZE.
<elf64-x86-64-sol2> (ELF_MAXPAGESIZE): Redefine
<elf32-x86-64> (ELF_MAXPAGESIZE): Restore previous value.
(ELF_MACHINE_CODE): Remove.
-rw-r--r-- | bfd/elf32-i386.c | 6 | ||||
-rw-r--r-- | bfd/elf64-x86-64.c | 11 |
2 files changed, 13 insertions, 4 deletions
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index abe26e4..b755b39 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -4586,6 +4586,9 @@ elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info) #undef TARGET_LITTLE_NAME #define TARGET_LITTLE_NAME "elf32-i386-sol2" +#undef ELF_MAXPAGESIZE +#define ELF_MAXPAGESIZE 0x10000 + #undef ELF_TARGET_OS #define ELF_TARGET_OS is_solaris @@ -4713,6 +4716,9 @@ elf32_iamcu_elf_object_p (bfd *abfd) #undef ELF_MACHINE_CODE #define ELF_MACHINE_CODE EM_IAMCU +#undef ELF_MAXPAGESIZE +#define ELF_MAXPAGESIZE 0x1000 + #undef ELF_TARGET_OS #undef ELF_OSABI diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index b6f97b5..b6fd466 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -6281,7 +6281,7 @@ elf_x86_64_special_sections[]= #define ELF_TARGET_ID X86_64_ELF_DATA #define ELF_MACHINE_CODE EM_X86_64 #define ELF_MAXPAGESIZE 0x1000 -#define ELF_COMMONPAGESIZE 0x1000 +#define ELF_COMMONPAGESIZE ELF_MAXPAGESIZE #define elf_backend_can_gc_sections 1 #define elf_backend_can_refcount 1 @@ -6392,7 +6392,10 @@ elf_x86_64_special_sections[]= #undef TARGET_LITTLE_NAME #define TARGET_LITTLE_NAME "elf64-x86-64-sol2" -#undef ELF_TARGET_OS +#undef ELF_MAXPAGESIZE +#define ELF_MAXPAGESIZE 0x100000 + +#undef ELF_TARGET_OS #define ELF_TARGET_OS is_solaris /* Restore default: we cannot use ELFOSABI_SOLARIS, otherwise ELFOSABI_NONE @@ -6453,8 +6456,8 @@ elf64_x86_64_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUS #undef ELF_ARCH #define ELF_ARCH bfd_arch_i386 -#undef ELF_MACHINE_CODE -#define ELF_MACHINE_CODE EM_X86_64 +#undef ELF_MAXPAGESIZE +#define ELF_MAXPAGESIZE 0x1000 #undef ELF_TARGET_OS #undef ELF_OSABI |