bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/31795] ld.bfd makes ELFs of type ET_EXEC for static PIEs when lo


From: mintsuki at protonmail dot com
Subject: [Bug ld/31795] ld.bfd makes ELFs of type ET_EXEC for static PIEs when load address is non-0
Date: Tue, 28 May 2024 15:27:57 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=31795

--- Comment #46 from mintsuki <mintsuki at protonmail dot com> ---
(In reply to H.J. Lu from comment #45)
> (In reply to mintsuki from comment #44)
> > (In reply to H.J. Lu from comment #43)
> > > (In reply to mintsuki from comment #42)
> > > > (In reply to H.J. Lu from comment #40)
> > > > > -Ttext-segment=0x600000000000 should create a binary which is 
> > > > > guaranteed to
> > > > > be
> > > > > loaded at 0x600000000000.
> > > > 
> > > > ...as long as it's not a PIE.
> > > 
> > > Please read x86-64 psABI:
> > > 
> > > https://gitlab.com/x86-psABIs/x86-64-ABI
> > > 
> > > PIE is the only way to create a small mode executable loaded at
> > > 0x600000000000.
> > 
> > Can you not use -mcmodel=large? In any case even if that was the case, it
> 
> There are 2 issues with -mcmodel=large:
> 
> 1. Since there are no -mcmodel=large run-time libraries, you can't use
> -mcmodel=large
> to create any meaningful binaries.
> 2. -mcmodel=large performance is much slower.
> 
> > should be opt-in to make the ELF ET_EXEC, rather than automatic and not
> > explicitly mentioned in a warning or anything.
> 
> Opt-in to ET_EXEC will be wrong.

Why will it be wrong? What if someone (me) wants to make a PIE that loads at a
minimum at the specified address, but can be relocated above it? Currently ld
makes this impossible by simply checking the ELF type, forcing my ELF loader to
additionally check for the presence of the DF_1_PIE flag to decide whether an
ELF file is relocatable or not...

...but Linux doesn't do that, apparently, but instead forces the load address
to be the one specified, due to the ELF type being ET_EXEC.

Earlier you said I should check DF_1_PIE to determine relocatability... so
which one is it? If I check for DF_1_PIE then I am not following the same
behaviour as the Linux ELF loader, which means that I either break from Linux's
behaviour, or I follow it, but that means that ld will never allow me to make
an ET_DYN PIE with a non-0 load address.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]