[PATCH] bfd: Fix Solaris/x86 ELF_MAXPAGESIZE
Rainer Orth
ro@CeBiTec.Uni-Bielefeld.DE
Mon Aug 18 14:39:14 GMT 2025
Hi Jan,
> On 15.08.2025 14:45, Rainer Orth wrote:
>> 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
>>
>> #define ELF_386_MAXPGSZ 0x10000
>> #define ELF_AMD64_MAXPGSZ 0x100000 /* maximum page size */
>>
>> while the Solaris/SPARC values are already correct.
>>
>> #define ELF_SPARC_MAXPGSZ 0x10000 /* maximum page size */
>> #define ELF_SPARCV9_MAXPGSZ 0x100000
>>
>> This patch fixes that. While on i386 it's sufficient to redefine
>> ELF_MAXPAGESIZE, x86_64 uses ELF_P_ALIGN instead.
>
> I don't quite follow this last sentence. ELF_P_ALIGN is used solely to set
> the p_align field in struct elf_backend_data. It's okay if that's what is
> needed for Solaris, but then the wording is a little odd and it remains
> unclear why i386 would be different in this regard.
the current patch was developped purely empirically, derived from the
observation that, unlike i386, just changing ELF_MAXPAGESIZE had no
effect on Solaris/amd64 p_align.
Comparing the gcc -g3 -E outputs between i386 and x86_64 (and the
ELF_P_ALIGN part of the current patch removed), I find what's going on
(using *_bed as markers):
* elf32-i386.c:
#define ELF_P_ALIGN ELF_MINPAGESIZE
#define ELF_MAXPAGESIZE 0x1000
#define elf32_bed elf32_i386_bed
#define ELF_COMMONPAGESIZE ELF_MAXPAGESIZE
#define ELF_MINPAGESIZE ELF_COMMONPAGESIZE
#undef ELF_MAXPAGESIZE
#define ELF_MAXPAGESIZE 0x10000
#undef elf32_bed
#define elf32_bed elf32_i386_sol2_bed
When ELF_P_ALIGN is used to initialize elf32_i386_sol2_bed, you get
the new/correct ELF_MAXPAGESIZE value as desired.
elf64-x86-64.c:
#define ELF_P_ALIGN ELF_MINPAGESIZE
#define ELF_MAXPAGESIZE 0x1000
#define ELF_COMMONPAGESIZE 0x1000
#undef elf64_bed
#define elf64_bed elf64_x86_64_bed
#define ELF_MINPAGESIZE ELF_COMMONPAGESIZE
#undef ELF_MAXPAGESIZE
#define ELF_MAXPAGESIZE 0x100000
#undef elf64_bed
#define elf64_bed elf64_x86_64_sol2_bed
However, here ELF_COMMONPAGESIZE is defined as 0x1000 (the default
value of ELF_MAXPAGESIZE), so redefining ELF_MAXPAGESIZE has no effect
on p_align as observed.
The simplest way to fix this seems to be to omit the ELF_P_ALIGN
redefinition part in elf64-x86-64.c from the current patch, instead
using the same
#define ELF_COMMONPAGESIZE ELF_MAXPAGESIZE
as in elf32-i386.c instead. This brings both targets in line, is a
no-op on non-Solaris x86_64 targets, and has the desired effect on
Solaris/amd64 p_align.
I've tested that already on amd64-pc-solaris2.11, x86_64-pc-linux-gnu,
and amd64-pc-freebsd14.0.
I this is deemed acceptable, I can resubmit that version.
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
More information about the Binutils
mailing list