[PATCH] D22683: [ELF] Symbol assignment within input section list

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 14:31:22 PDT 2016


On Tue, Aug 2, 2016 at 3:00 AM, Eugene Leviant <evgeny.leviant at gmail.com>
wrote:

> evgeny777 added a comment.
>
> I think the main reason, we're using virtual input sections is that this
> the only way to calculate correct symbol offset. As you may know location
> counter is not incremented while we add input sections to output section,
> and the true size of input sections is known only after call to
> OutputSectionBase<ELFT>::assignOffsets().
>
> So if you suggest an algorithm, which can calculate correct symbol value
> (w/o using virtual input sections) in the case below:
>
>   .foo : { *(.foo); end_foo = .; *(.bar) }
>
> then we can probably switch to absolute symbols (BTW we can also use
> synthetic symbols - there is a little difference, if any).
> Another interesting question is what will happen if we define absolute
> symbol in shared object and reference it in executable? For example:
>
>   /* script for linking shared library */
>   SECTIONS { .text : { text_start = .; *(.text) } }
>
> So, when shared library is loaded by application, what value would
> text_start have, in case it is absolute? I don't know yet, but will try.
>

At first, I suggested you use empty dummy input sections to define
linker-script-defined symbols in the hope that in that way we don't need to
fix symbol addresses later (I was hoping that symbol addresses are
automatically fixed as attached input sections get final output addresses.)
Now that we know it doesn't work for many possible use cases. Then maybe we
want to eliminated dummy sections and directly define symbols as absolute
(or section) symbols.

In this patch, you are trying to support assignments to symbols. However,
we eventually want to support something like this, too.

  SECTIONS { .text : { foo.o(.text); . = ALIGN(128); bar.o(.text) } }

Looks like this doesn't fit to the current architecture. Currently, we
create a list of input sections and assign them addresses later. But in
order to process the above script, one pass would fit well. So I'm
wondering if we should merge LinkerScript::createSections and
LinkerScript::assignOffsets.


>
> ================
> Comment at: ELF/LinkerScript.cpp:278
> @@ -176,3 +277,3 @@
>  // Process ONLY_IF_RO and ONLY_IF_RW.
>  template <class ELFT> void LinkerScript<ELFT>::filter() {
>    // In this loop, we remove output sections if they don't satisfy
> ----------------
> ruiu wrote:
> > Why did you have to make a change to this function?
> Two main reasons:
>
> 1) During filtering process some output sections may be removed. Those
> sections may contain symbols and SymbolInputSection object have already
> been created for them. To avoid crashes and/or creating dummy symbols I
> have to remove those virtual sections as well
>
> 2) The old implementation is not technically correct, because it removes
> only first output section found in name lookup. We're still using
> OutputSectionFactory<ELFT>, so we may have several sections with the same
> name.
>
> Another reason (though much less significant) is that one-by-one removal
> from std::vector must be slow, because it stores elements on continuous
> region of memory.
>
>
> https://reviews.llvm.org/D22683
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160802/9a4852fb/attachment.html>


More information about the llvm-commits mailing list