Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create new segment in linker script while keeping default ones

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?

like image 853
xywang Avatar asked Mar 15 '17 11:03

xywang


People also ask

How do I find the default linker script?

You can use the ` --verbose ' command line option to display the default linker script. Certain command line options, such as ` -r ' or ` -N ', will affect the default linker script.

What is keep in linker script?

The KEEP statement within a linker script will instruct the linker to keep the specified section, even if no symbols inside it are referenced. This statement is used within the SECTIONS section of the linker script.

How do you make a linker script?

You write a linker script as a series of commands. Each command is either a keyword, possibly followed by arguments, or an assignment to a symbol. You may separate commands using semicolons. Whitespace is generally ignored.

What is Section in linker?

The SECTIONS command tells the linker how to map input sections into output sections, and how to place the output sections in memory. The format of the SECTIONS command is: SECTIONS { sections-command sections-command … }


1 Answers

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.

like image 86
HardcoreHenry Avatar answered Oct 03 '22 01:10

HardcoreHenry