[PATCH] D29653: [ELF] - Assign proper values for DefinedSynthetic symbols attached to non-allocatable sections.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 7 09:48:54 PST 2017


LGTM.

An interesting experiment would be to keep the fake section address
until the last minute, but this is the simplest way of getting the test
passing.

Cheers,
Rafael

George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> grimar updated this revision to Diff 87464.
> grimar edited the summary of this revision.
> grimar added a comment.
>
> - Addressed review comments (changes testcase to avoid depending on orphans).
>
>
> https://reviews.llvm.org/D29653
>
> Files:
>   ELF/LinkerScript.cpp
>   test/ELF/linkerscript/symbols-and-orphans.s
>
>
> Index: test/ELF/linkerscript/symbols-and-orphans.s
> ===================================================================
> --- test/ELF/linkerscript/symbols-and-orphans.s
> +++ test/ELF/linkerscript/symbols-and-orphans.s
> @@ -0,0 +1,16 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> +
> +# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; \
> +# RUN:  .text : { *(.text) }                \
> +# RUN:  .nonalloc : { *(.nonalloc) }        \
> +# RUN:  Sym = .;                            \
> +# RUN:  }" > %t.script
> +# RUN: ld.lld -o %t2 --script %t.script %t
> +# RUN: llvm-objdump -section-headers -t %t2 | FileCheck %s
> +
> +# CHECK: SYMBOL TABLE:
> +# CHECK:  00000000000000f0 .nonalloc 00000000 Sym
> +
> +.section .nonalloc,""
> + .quad 0
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -101,8 +101,12 @@
>  
>    if (auto *Body = dyn_cast<DefinedSynthetic>(Cmd->Sym)) {
>      Body->Section = Cmd->Expression.Section();
> -    if (Body->Section)
> -      Body->Value = Cmd->Expression(Dot) - Body->Section->Addr;
> +    if (Body->Section) {
> +      uint64_t VA = 0;
> +      if (Body->Section->Flags & SHF_ALLOC)
> +        VA = Body->Section->Addr;
> +      Body->Value = Cmd->Expression(Dot) - VA;
> +    }
>      return;
>    }
>  
>
>
> Index: test/ELF/linkerscript/symbols-and-orphans.s
> ===================================================================
> --- test/ELF/linkerscript/symbols-and-orphans.s
> +++ test/ELF/linkerscript/symbols-and-orphans.s
> @@ -0,0 +1,16 @@
> +# REQUIRES: x86
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
> +
> +# RUN: echo "SECTIONS { . = SIZEOF_HEADERS; \
> +# RUN:  .text : { *(.text) }                \
> +# RUN:  .nonalloc : { *(.nonalloc) }        \
> +# RUN:  Sym = .;                            \
> +# RUN:  }" > %t.script
> +# RUN: ld.lld -o %t2 --script %t.script %t
> +# RUN: llvm-objdump -section-headers -t %t2 | FileCheck %s
> +
> +# CHECK: SYMBOL TABLE:
> +# CHECK:  00000000000000f0 .nonalloc 00000000 Sym
> +
> +.section .nonalloc,""
> + .quad 0
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -101,8 +101,12 @@
>  
>    if (auto *Body = dyn_cast<DefinedSynthetic>(Cmd->Sym)) {
>      Body->Section = Cmd->Expression.Section();
> -    if (Body->Section)
> -      Body->Value = Cmd->Expression(Dot) - Body->Section->Addr;
> +    if (Body->Section) {
> +      uint64_t VA = 0;
> +      if (Body->Section->Flags & SHF_ALLOC)
> +        VA = Body->Section->Addr;
> +      Body->Value = Cmd->Expression(Dot) - VA;
> +    }
>      return;
>    }
>  


More information about the llvm-commits mailing list