6

I have created some special sections in a linked file and I want them to be in separated segments to have different page permissions.

In linker script, PHDRS command can specify segments in linked file. However, as the document says, PHDRS will create no default-defined segments other than specified in the command. And I found no PHDRS command in ld --verbose output.

Is there any way to keep the default ones? Or what is the default specifications of segments so I can write them in my own linker script?

1
  • There's a writeup on how to tackle this problem by Stephen Krell over here. They also provide code. I'm sharing the link as a comment and not an answer because the approach shown is a workaround rather than a standard approach provided by the ld linker.
    – Jet Blue
    Commented Feb 24, 2020 at 0:56

1 Answer 1

2

Came across this when looking for similar answers. It's late, but someone else might come across it. To get the currently used linker script you can use gcc -Wl,--verbose ... or ld --verbose ... when linking, which will dump the script (and a bunch of other stuff) to stdout. As far as I'm aware, there is no way to keep the default program headers and just append an entry to them without writing a custom script to parse the output of the above. If you want to add a section on the other hand, apparently there's a trick with objcopy --add-section that allows you to add a section to an existing elf file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.