Summer_More_More_Tea
Summer_More_More_Tea

Reputation: 13436

How to link segments with the same type but different flags from different object files (ELF)?

I'm curious about how does a linker link segments with same type but different flags from different object files. E.g. we now have two ELF object files foo.o and bar.o, both of which have a .text segment (code segment). However, .text segment in foo.o is write-able while that in bar.o is not. In this case, how will the linker link these two segments? How will the linker set the flag of the .text segment in the linked file?

Thanks and Best regards!

Upvotes: 0

Views: 254

Answers (1)

Employed Russian
Employed Russian

Reputation: 213897

How will the linker set the flag of the .text segment in the linked file?

There is no .text segment in the linked file: the .text section is put into one of the LOAD segments.

The linker can choose what to do.

  • it can create multiple .text sections with different flags, and put them into multiple LOAD segments.
  • it can merge all .text sections from foo.o and bar.o into a single .text section, and make it writable
  • it can fail the link

Upvotes: 1

Related Questions