Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,13 +1756,21 @@ static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
sym = ctx.symtab->insert(objSym.getName());
}

int c = objSym.getComdatIndex();
if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {
if (objSym.isUndefined()) {
Undefined newSym(&f, StringRef(), binding, visibility, type);
sym->resolve(ctx, newSym);
sym->referenced = true;
return;
}
int c = objSym.getComdatIndex();
if (c != -1 && !keptComdats[c]) {
Defined newSym(ctx, &f, StringRef(), binding, visibility, type, 0, 0, nullptr);
if (objSym.canBeOmittedFromSymbolTable())
newSym.exportDynamic = false;
sym->resolve(ctx, newSym);
sym->referenced = true;
return;
}

if (objSym.isCommon()) {
sym->resolve(ctx, CommonSymbol{ctx, &f, StringRef(), binding, visibility,
Expand Down
36 changes: 36 additions & 0 deletions lld/test/ELF/lto/comdat-weakodr-linkonceodr-visibility.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
; RUN: rm -rf %t.dir
; RUN: split-file %s %t.dir
; RUN: cd %t.dir
; RUN: echo %t.dir
; RUN: llvm-as explicit.ll -o explicit.bc
; RUN: llvm-as implicit.ll -o implicit.bc


;; Case 1:
; RUN: ld.lld explicit.bc implicit.bc -o case1.so -shared -save-temps
; RUN: llvm-nm case1.so.0.2.internalize.bc | FileCheck %s

;; Case 2:
; RUN: ld.lld implicit.bc explicit.bc -o case2.so -shared -save-temps
; RUN: llvm-nm case2.so.0.2.internalize.bc | FileCheck %s

; CHECK: W foo

;--- explicit.ll
target triple = "x86_64-unknown-linux-gnu"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

$foo = comdat any
define weak_odr void @foo() local_unnamed_addr comdat {
ret void
}


;--- implicit.ll
target triple = "x86_64-unknown-linux-gnu"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

$foo = comdat any
define linkonce_odr void @foo() local_unnamed_addr comdat {
ret void
}
Loading