[PATCH] D23565: [ELF] Linkerscript: fix relocation offsets

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 17 00:45:15 PDT 2016


evgeny777 added a comment.

Let me elaborate a little bit:
Roughly current workflow is like following:

Create output sections (createSections) -> Scan relocations (scanRelocs) -> Assign output section VA (assignAddresses)

The current implementation of scanRelocs assumes that output section sizes and input section offsets are already known. This is not always true when linker scripts are used.
For example this script creates output section .foo, which size depends on its own virtual address:

  .foo : {
     *(.foo)
     . = ALIGN(0x1000); /* this line creates gap inside the output section .foo, which size depends on .foo virtual address */
     *(.bar)
  }

This means that in case of linker script we only know exact size of the output and offset of the inputs after call to assignAddresses().
At the same time scanRelocs() cannot be called from assignAddresses(), because scanRelocs() creates and fills some predefined sections (.got, .rela.dyn, .got.plt),
and all sections must be created before assignAddresses() is called.

To my understanding some refactoring to the whole workflow is needed, which would probably look like this:

createSections() -> createRelocs() -> assignAddresses() -> assignRelocs()

This patch is just a quick fix for a specific problem.


https://reviews.llvm.org/D23565





More information about the llvm-commits mailing list