[ipxe-devel] gcc defaults to pie ?

Joakim Tjernlund Joakim.Tjernlund at infinera.com
Wed Jan 31 17:31:47 UTC 2018

On Thu, 1970-01-01 at 00:00 +0000, Michael Brown wrote:
> On 31/01/18 17:05, Joakim Tjernlund wrote:
> > On Thu, 1970-01-01 at 00:00 +0000, Michael Brown wrote:
> > > There's logic within arch/i386/Makefile which is supposed to autodetect
> > > compilers that do this and specify the appropriate combination of "do
> > > not use PIE" options.  We may need to expand this to handle whatever
> > > Gentoo has done.
> > 
> > Does that apply to every file that is built? arch/i386/Makefile feel specific for
> > i386.
> It applies to every file built for the (standard) i386 BIOS build.
> To hit an error relating to "code model kernel" I think you must be
> trying to build for the x86_64-pcbios platform, since that's the only
> place I can find that we use an explicit -mcmodel=kernel.

Yes, building on x86_64 for x86_64, various targets, for example
make -j1 Q=''   CC=x86_64-pc-linux-gnu-gcc LD=x86_64-pc-linux-gnu-ld AS=x86_64-pc-linux-gnu-as AR=x86_64-pc-
linux-gnu-ar NM=x86_64-pc-linux-gnu-nm OBJCOPY=x86_64-pc-linux-gnu-objcopy RANLIB=x86_64-pc-linux-gnu-ranlib
OBJDUMP=x86_64-pc-linux-gnu-objdump HOST_CC=x86_64-pc-linux-gnu-gcc ARCH=x86_64
EMBED=/var/lib/layman/transmode/profiles/gentoo64-common/IPXE.script bin/808610de.rom

> The x86_64-pcbios platform is fairly obscure: it produces code that runs
> in 64-bit long mode but using 16-bit BIOS calls for console I/O and
> providing 16-bit real-mode entry points for PXE NBPs.  You only really
> need this platform if you are going to end up with your PCI BARs
> allocated above 4GB.
> > > There's similar logic in Makefile.housekeeping to disable
> > > -fstack-protector if needed.
> > 
> > I see that, should Makefile.housekeeping include -U_FORTIFY_SOURCE then?
> I don't think so.  The FORTIFY_SOURCE macro will be completely ignored
> by all of the iPXE source files, and there are no external libraries
> linked in anyway.

OK, just want to be extra careful as Gentoo default to fortify on too.

> > Also, ATM one cannot pass flags into ipxe due to:
> > CFLAGS                :=
> > can it be changed to
> > CFLAGS                ?=
> You can use EXTRA_CFLAGS to insert additional flags.  These will be
> placed after CFLAGS, which makes it possible to use EXTRA_CFLAGS to
> override Makefile-generated flags.

I see, will try that. However, CFLAGS is normally reserved for users so I still think
CFLAGS ?= is a good ide.
Combining that with EXTRA_CFLAGS makes it possible to prepend and append flags.

More information about the ipxe-devel mailing list