[PATCH] D62177: [ELF] Don't advance position in a memory region when assigning to the Dot
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 21 02:00:57 PDT 2019
MaskRay added a comment.
In D62177#1509729 <https://reviews.llvm.org/D62177#1509729>, @grimar wrote:
> I find the behavior of the GNU linkers wierd.
>
> If we use bfd and have:
>
> .section .foo,"ax";
> nop;
>
> .section .bar,"ax";
> nop;
>
>
> and script:
>
> MEMORY {
> ram (ax) : ORIGIN = 0x42000, LENGTH = 0x100000
> }
> SECTIONS {
> .foo : { *(.foo*) }
> . += 0x2000;
> .bar : { *(.bar*) }
> }
>
>
> Then `.foo` section has address 0x42000 and `.bar` has 0x42001.
> I.e. moving a dot does not change the address of the next section.
>
> But if I remove `MEMORY`:
>
> SECTIONS {
> .foo : { *(.foo*) }
> . += 0x2000;
> .bar : { *(.bar*) }
> }
>
>
> Then `.foo` is `0x0` and `.bar` is `0x2001` (as I would expect to see)
>
> I think it is very strange that `MEMORY` command affects the Dot assignment behavior in that way.
>
> Seems that original script from PR had to use a hack to move the second output section:
>
> aligned_dot = ALIGN(0x10 * 1024);
>
> .data aligned_dot :
> {
> *(.data*)
> }
>
I agree... The code near `gold/script-sections.cc:2476` (in `Output_section_definition::set_section_addresses`) is responsible for this behavior
vma_region = script_sections->find_memory_region(this, true, false, NULL);
if (vma_region != NULL) ////////// if it can find a matched memory region, dot_value will be ignored.
address = vma_region->get_current_address()->eval(symtab, layout,
false);
else
address = *dot_value;
Our code responsible for this behavior is:
if (Ctx->MemRegion)
Dot = Ctx->MemRegion->CurPos;
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62177/new/
https://reviews.llvm.org/D62177
More information about the llvm-commits
mailing list