Help needed - defining the output section order

Segher Boessenkool segher@kernel.crashing.org
Wed Aug 24 15:55:00 GMT 2005


> SB> It might be enough if you prevent ld from creating the magic stack
> SB> segment behind its own back, e.g., I have this in my Makefiles:
>
> SB> %.o: %.c
> SB>          $(CC) $(CFLAGS) -c $< -o $@ && $(OBJCOPY) -R 
> .note.GNU-stack $@
>
> SB> (using /DISCARD/ in your linker script is _not_ enough).
>
> This sounds very interesting - however, I have to admit I don't know
> much about makefile syntax and/or gcc options - I'm a pascal guy,
> after all ;). To which ld options would this translate to?

Not an ld option; instead, you run an objcopy command on every
object file, before you link them together.  An example is

	objcopy -R .note.GNU-stack example.o

Do this on _every_ object file that is used in the link.

Some background: if ld sees a .note.GNU-stack note section in
all of the input files, it puts a GNU_STACK segment into the
output file automagically.  Linux uses this information to make
the stack non-executable.  But this automatic generation of a
PHDR seems to screw up the precomputed count of PHDRS.  Maybe
we can call this a bug, even?


Segher



More information about the Binutils mailing list