From 1b625535f0bd8d00a4b6d9fa53a8010c291fd6f3 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 29 Feb 2016 14:29:48 +0000 Subject: [PATCH] lto: don't fetch members for weak undef. llvm-svn: 262225 --- lld/ELF/InputFiles.cpp | 6 +++--- lld/test/ELF/lto/undef-weak.ll | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 lld/test/ELF/lto/undef-weak.ll diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 5f5ac9e..78abcf9 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -454,11 +454,11 @@ void BitcodeFile::parse() { StringRef NameRef = Saver.save(StringRef(Name)); SymbolBody *Body; uint32_t Flags = Sym.getFlags(); + bool IsWeak = Flags & BasicSymbolRef::SF_Weak; if (Flags & BasicSymbolRef::SF_Undefined) - Body = new (Alloc) Undefined(NameRef, false, STV_DEFAULT, false); + Body = new (Alloc) Undefined(NameRef, IsWeak, STV_DEFAULT, false); else - Body = - new (Alloc) DefinedBitcode(NameRef, Flags & BasicSymbolRef::SF_Weak); + Body = new (Alloc) DefinedBitcode(NameRef, IsWeak); SymbolBodies.push_back(Body); } } diff --git a/lld/test/ELF/lto/undef-weak.ll b/lld/test/ELF/lto/undef-weak.ll new file mode 100644 index 0000000..215978a --- /dev/null +++ b/lld/test/ELF/lto/undef-weak.ll @@ -0,0 +1,29 @@ +; REQUIRES: x86 + +; RUN: llvm-as %S/Inputs/archive.ll -o %t1.o +; RUN: rm -f %t.a +; RUN: llvm-ar rcs %t.a %t1.o + + +; RUN: llvm-as %s -o %t2.o +; RUN: ld.lld -m elf_x86_64 %t2.o -o %t2.so %t.a -shared +; RUN: llvm-readobj -t %t2.so | FileCheck %s +target triple = "x86_64-unknown-linux-gnu" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +declare extern_weak void @f() +define void @foo() { + call void @f() + ret void +} + +; We should not fetch the archive member. + +; CHECK: Name: f ({{.*}}) +; CHECK-NEXT: Value: 0x0 +; CHECK-NEXT: Size: 0 +; CHECK-NEXT: Binding: Weak +; CHECK-NEXT: Type: None +; CHECK-NEXT: Other: 0 +; CHECK-NEXT: Section: Undefined + -- 2.7.4