1
votes

When I link together object files, the resulting ELF executable has (only) the following LOAD segment:

LOAD off    0x00000000 vaddr 0x00008000 paddr 0x00008000 align 2**15
     filesz 0x000010f0 memsz 0x000010f0 flags rwx

The linker ld combined all sections into one rwx segment, instead of separating writable and executable parts. I want to prevent this. The relocatable objects have the sections marked as writable or executable as appropriate, so this problem appears at the link time.

So, what determines how ld assigns permissions to the segments? The linker script does not seem to have anything related to that. Is it something specified when the toolchain is built?

I am targeting the ARM, and the toolchain is arm-linux-gnueabi, binutils version 2.22.

Edit: The linker script is here. The other linker options are -Bdynamic, --gc-sections, -z nocopyreloc and --no-undefined.

1
It seems to depend on the linker. An arm-eabi ld produced executables with the segments separated, even with the same linker script. I still don't know what specifies this. - Juho Östman
please post your linker script the answer to your question is there, cant do much without that unless you are overriding it with the command line and in that case post the command line. very possible and quite easy to separate sections at will...in the linker script... - old_timer
added the script and the options - Juho Östman

1 Answers

1
votes

Usually linker scripts are used to define sections, their order, whether to keep them or trash them from the binary (release build linker script might chose to remove debugging info).

Here is an example of a linker script: system-onesegment.ld

EDIT: to modify section permission, put this before whatever section you want to change the permission of .section .section_name, "permission".

Example:

.text
mov r0, r0
b main
.section .rodata, "ro"
.word 0x00000001
.previous
main: mov r0, r0