1

I defined a new code section in my assembly program, which is going to be compiled into 32-bit ELF binary, on x86.

I use the linker scripts to assign a specified address for this new code section, it works. However, I noticed that this new section does not be loaded to the memory, after some debugging!

I use readelf and figure out that there is no "execution" privilege of this new section:

[15] .trampoline       PROGBITS        080483d0 004020 000117 00      0   0 16

Then I did this:

objcopy --set-section-flags .trampoline=alloc,code a.out

However, I got this warning:

BFD: stQWykoH: warning: allocated section `.trampoline' not in segment

Now I realize that I didn't explicitly assign a segment information to my new section!!

So here is my question:

  1. How to assign a segment information to a new code section I defined? I double-checked the linker script (follow instruction here to dump), and I have no idea how to modify the script...

  2. I just want to add a new executable section to my assembly program, and assign a fixed address to this new section. So am I on the right way now?

Community
  • 1
  • 1
lllllllllllll
  • 8,519
  • 9
  • 45
  • 80
  • 1
    I think if your section have A flag it loaded into memory, so please post your section flags into problem. see [this](https://sourceware.org/binutils/docs/ld/Output-Section-Attributes.html#Output-Section-Attributes) for setting section attribute in linker script – Parham Alvani Feb 10 '15 at 19:46
  • 1
    You can define the flags for your section in the assembly source, no need to mess with linker scripts (see your assembler's manual, at least `nasm` and `gas` allow this). Also you can set a section address on the linker command line. Avoid linker scripts if you can, LOL. – Jester Feb 10 '15 at 19:48
  • So after that your section is Allocated in memory and you have Write and eXecute permission on it so you can use linker script [Entry](https://sourceware.org/binutils/docs/ld/Entry-Point.html#Entry-Point) command to start your program from your section. – Parham Alvani Feb 10 '15 at 20:04

0 Answers0