[llvm] r300205 - LTO: Pass SF_Executable flag through to InputFile::Symbol
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 10:51:12 PDT 2017
On Thu, Apr 13, 2017 at 9:24 AM, Tobias Edler von Koch via
llvm-commits <llvm-commits at lists.llvm.org> wrote:
> Author: tobiasvk
> Date: Thu Apr 13 11:24:14 2017
> New Revision: 300205
>
> URL: http://llvm.org/viewvc/llvm-project?rev=300205&view=rev
> Log:
> LTO: Pass SF_Executable flag through to InputFile::Symbol
>
> Summary:
> The linker needs to be able to determine whether a symbol is text or data to
> handle the case of a common being overridden by a strong definition in an
> archive. If the archive contains a text member of the same name as the common,
> that function is discarded. However, if the archive contains a data member of
> the same name, that strong definition overrides the common. This is a behavior
> of ld.bfd, which the Qualcomm linker also supports in LTO.
>
> Here's a test case to illustrate:
>
> ####
>
> cat > 1.c << \!
> int blah;
> !
>
> cat > 2.c << \!
> int blah() {
> return 0;
> }
> !
>
> cat > 3.c << \!
> int blah = 20;
> !
>
> clang -c 1.c
> clang -c 2.c
> clang -c 3.c
>
> ar cr lib.a 2.o 3.o
> ld 1.o lib.a -t
>
> ####
>
> The correct output is:
>
> 1.o
> (lib.a)3.o
>
> Thanks to Shankar Easwaran and Hemant Kulkarni for the test case!
>
> Reviewers: mehdi_amini, rafael, pcc, davide
>
> Reviewed By: pcc
>
> Subscribers: davide, llvm-commits, inglorion
>
> Differential Revision: https://reviews.llvm.org/D31901
>
> Modified:
> llvm/trunk/include/llvm/LTO/LTO.h
> llvm/trunk/include/llvm/Object/IRSymtab.h
> llvm/trunk/lib/Object/IRSymtab.cpp
> llvm/trunk/test/LTO/Resolution/X86/symtab.ll
> llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
>
> Modified: llvm/trunk/include/llvm/LTO/LTO.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTO.h?rev=300205&r1=300204&r2=300205&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/LTO/LTO.h (original)
> +++ llvm/trunk/include/llvm/LTO/LTO.h Thu Apr 13 11:24:14 2017
> @@ -126,6 +126,7 @@ public:
> using irsymtab::Symbol::getCommonSize;
> using irsymtab::Symbol::getCommonAlignment;
> using irsymtab::Symbol::getCOFFWeakExternalFallback;
> + using irsymtab::Symbol::isExecutable;
> };
>
> /// A range over the symbols in this InputFile.
>
> Modified: llvm/trunk/include/llvm/Object/IRSymtab.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/IRSymtab.h?rev=300205&r1=300204&r2=300205&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Object/IRSymtab.h (original)
> +++ llvm/trunk/include/llvm/Object/IRSymtab.h Thu Apr 13 11:24:14 2017
> @@ -92,6 +92,7 @@ struct Symbol {
> FB_global,
> FB_format_specific,
> FB_unnamed_addr,
> + FB_executable,
> };
>
> /// The index into the Uncommon table, or -1 if this symbol does not have an
> @@ -166,6 +167,7 @@ struct Symbol {
> bool isGlobal() const { return (Flags >> S::FB_global) & 1; }
> bool isFormatSpecific() const { return (Flags >> S::FB_format_specific) & 1; }
> bool isUnnamedAddr() const { return (Flags >> S::FB_unnamed_addr) & 1; }
> + bool isExecutable() const { return (Flags >> S::FB_executable) & 1; }
>
> uint64_t getCommonSize() const {
> assert(isCommon());
>
> Modified: llvm/trunk/lib/Object/IRSymtab.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/IRSymtab.cpp?rev=300205&r1=300204&r2=300205&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Object/IRSymtab.cpp (original)
> +++ llvm/trunk/lib/Object/IRSymtab.cpp Thu Apr 13 11:24:14 2017
> @@ -125,6 +125,8 @@ Error Builder::addSymbol(ModuleSymbolTab
> Sym.Flags |= 1 << storage::Symbol::FB_global;
> if (Flags & object::BasicSymbolRef::SF_FormatSpecific)
> Sym.Flags |= 1 << storage::Symbol::FB_format_specific;
> + if (Flags & object::BasicSymbolRef::SF_Executable)
> + Sym.Flags |= 1 << storage::Symbol::FB_executable;
>
> Sym.ComdatIndex = -1;
> auto *GV = Msym.dyn_cast<GlobalValue *>();
>
> Modified: llvm/trunk/test/LTO/Resolution/X86/symtab.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/Resolution/X86/symtab.ll?rev=300205&r1=300204&r2=300205&view=diff
> ==============================================================================
> --- llvm/trunk/test/LTO/Resolution/X86/symtab.ll (original)
> +++ llvm/trunk/test/LTO/Resolution/X86/symtab.ll Thu Apr 13 11:24:14 2017
> @@ -11,37 +11,42 @@ source_filename = "src.c"
> !0 = !{i32 6, !"Linker Options", !{!{!"/include:foo"}}}
> !llvm.module.flags = !{ !0 }
>
> -; CHECK: H------ _g1
> +; CHECK: D------X _fun
> +define i32 @fun() {
> + ret i32 0
> +}
> +
> +; CHECK: H------- _g1
> @g1 = hidden global i32 0
>
> -; CHECK: P------ _g2
> +; CHECK: P------- _g2
> @g2 = protected global i32 0
>
> -; CHECK: D------ _g3
> +; CHECK: D------- _g3
> @g3 = global i32 0
>
> -; CHECK: DU----- _g4
> +; CHECK: DU------ _g4
> @g4 = external global i32
>
> -; CHECK: D--W--- _g5
> +; CHECK: D--W---- _g5
> @g5 = weak global i32 0
>
> -; CHECK: D--W-O- _g6
> +; CHECK: D--W-O-- _g6
> @g6 = linkonce_odr unnamed_addr global i32 0
>
> -; CHECK: D-----T _g7
> +; CHECK: D-----T- _g7
> @g7 = thread_local global i32 0
>
> -; CHECK: D-C---- _g8
> +; CHECK: D-C----- _g8
> ; CHECK-NEXT: size 4 align 8
> @g8 = common global i32 0, align 8
>
> -; CHECK: D------ _g9
> +; CHECK: D------- _g9
> ; CHECK-NEXT: comdat g9
> $g9 = comdat any
> @g9 = global i32 0, comdat
>
> -; CHECK: D--WI-- _g10
> +; CHECK: D--WI--- _g10
> ; CHECK-NEXT: comdat g9
> ; CHECK-NEXT: fallback _g9
> @g10 = weak alias i32, i32* @g9
>
> Modified: llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp?rev=300205&r1=300204&r2=300205&view=diff
> ==============================================================================
> --- llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp (original)
> +++ llvm/trunk/tools/llvm-lto2/llvm-lto2.cpp Thu Apr 13 11:24:14 2017
> @@ -317,18 +317,19 @@ static int dumpSymtab(int argc, char **a
> PrintBool('I', Sym.isIndirect());
> PrintBool('O', Sym.canBeOmittedFromSymbolTable());
> PrintBool('T', Sym.isTLS());
> + PrintBool('X', Sym.isExecutable());
> outs() << ' ' << Sym.getName() << '\n';
>
> if (Sym.isCommon())
> - outs() << " size " << Sym.getCommonSize() << " align "
> + outs() << " size " << Sym.getCommonSize() << " align "
> << Sym.getCommonAlignment() << '\n';
>
> int Comdat = Sym.getComdatIndex();
> if (Comdat != -1)
> - outs() << " comdat " << ComdatTable[Comdat] << '\n';
> + outs() << " comdat " << ComdatTable[Comdat] << '\n';
>
> if (Sym.isWeak() && Sym.isIndirect())
> - outs() << " fallback " << Sym.getCOFFWeakExternalFallback() << '\n';
> + outs() << " fallback " << Sym.getCOFFWeakExternalFallback() << '\n';
> }
>
> outs() << '\n';
These seem to be unrelated formatting changes. Are them intended?
--
Davide
"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare
More information about the llvm-commits
mailing list