5

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?

xywang
  • 841
  • 5
  • 17
  • There's a writeup on how to tackle this problem by Stephen Krell over [here](https://www.cs.kent.ac.uk/people/staff/srk21/blog/2017/02/14/). 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 Feb 24 '20 at 00:56

1 Answers1

1

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.

HardcoreHenry
  • 3,775
  • 2
  • 11
  • 33