[PATCH] D31888: [LLD][ELF] Always use Script::assignAddresses()

ben via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 03:16:48 PDT 2017


bd1976llvm added a comment.

I *really* like this change. There should be only one function that assigns addresses.

I am also maintaining support for a target that does not allocate headers. Here are the modifications that I have made in case they are useful to someone else:

1. Change the call to fabricateDefaultCommands() to take false.
2. Remove the call to allocateHeaders() at the end of assignAddresses().
3. Modify allocateHeaders() to return early after doing:



  Out::ElfHeader->Addr = Min;
  Out::ProgramHeaders->Addr = Min + Out::ElfHeader->Size;

but before doing:

  if (FirstPTLoad->First)
    for (OutputSection *Sec : OutputSections)
      if (Sec->FirstInPtLoad == FirstPTLoad->First)
        Sec->FirstInPtLoad = Out::ElfHeader;
  FirstPTLoad->First = Out::ElfHeader;
  if (!FirstPTLoad->Last)
    FirstPTLoad->Last = Out::ProgramHeaders;
  return true;

The question I am struggling with is: Why is allocateHeaders called twice? Could the function fixHeaders() be removed?

There is a comment in Writer.cpp claiming that:

// The headers have to be created before finalize as that can influence the image base and the dynamic section on mips includes the image base.

Is this actually a hard requirement? Surely, given that this is a linker (where one of its principle jobs is to write addresses into holes after the program has been laid out) we can fix up this section later on?

If there is someone who knows this area of the code it would be very much appreciated if they could comment on this.

Thanks in advance!


Repository:
  rL LLVM

https://reviews.llvm.org/D31888





More information about the llvm-commits mailing list