This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Don't create PT_LOAD's when linking script is used.
AbandonedPublic

Authored by grimar on Mar 21 2016, 8:14 AM.

Details

Reviewers
ruiu
rafael
Summary

Actually patch is more about that we should not align the PT_LOAD's created
if we use linker script. That is the main aim of this patch.
(we dont want to touch the location counter when we use script)

I don't have strong opinion about creating PT_LOAD's as ld and gold do diffterent things that
both looks ok for me.
Please see below:

Consider the next code and empty linker script file..
main.s:

.globl _start;
_start:
nop

.section .data
.quad 0

llvm-mc -filetype=obj -triple=x86_64-pc-linux main.s -o main.o
gold main.o -script empty.script -o test

produces 2 Loads without allignment of VA's:

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                 0x00000000000000b1 0x00000000000000b1  R E    1000
  LOAD           0x00000000000000b1 0x00000000004010b1 0x00000000004010b1
                 0x0000000000000008 0x0000000000000008  RW     1000

GNU ld has another output here:
ld main.o -script empty.script -o test
Program Headers:

Type           Offset             VirtAddr           PhysAddr
               FileSiz            MemSiz              Flags  Align
LOAD           0x0000000000200000 0x0000000000000000 0x0000000000000000
               0x0000000000000009 0x0000000000000009  RWE    200000

So there is a single PT_LOAD with flags combined.

This patch implements the same behavior as ld do.

Diff Detail

Event Timeline

grimar updated this revision to Diff 51164.Mar 21 2016, 8:14 AM
grimar retitled this revision from to [ELF] - Don't create PT_LOAD's when linking script is used..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
ruiu edited edge metadata.Mar 21 2016, 11:51 AM

I think this patch implemented an edge case of the linker script. The general case is that, if a linker script is given, then section layout needs to be determined by the script. Once we implement the linker script support, I don't think it would execute this code path because we would have a different code path for the linker script. In that sense this patch does not solve a problem or prepare for the linker script support.

In D18317#379575, @ruiu wrote:

I think this patch implemented an edge case of the linker script. The general case is that, if a linker script is given, then section layout needs to be determined by the script. Once we implement the linker script support, I don't think it would execute this code path because we would have a different code path for the linker script. In that sense this patch does not solve a problem or prepare for the linker script support.

Well, I don't want argue with that now. I hope tomorrow will post a patch for initial location counter support (from linker script). Lets then return back to this after that.

In D18317#379575, @ruiu wrote:

I think this patch implemented an edge case of the linker script. The general case is that, if a linker script is given, then section layout needs to be determined by the script. Once we implement the linker script support, I don't think it would execute this code path because we would have a different code path for the linker script. In that sense this patch does not solve a problem or prepare for the linker script support.

So sorry, I am a bit late with that, but I finally posted a patch implementing few ideas about initial location counter support and this one is a dependency :)
(http://reviews.llvm.org/D18499)

emaste added a subscriber: emaste.Mar 27 2016, 7:21 AM
grimar abandoned this revision.Mar 30 2016, 2:12 AM

This one not correct, we *should* create PT_LOADs. What we want is not to change VA (align to PT_LOAD etc) when using linkerscript still, I'll post different version for that.