Skip to content

[ELF] Respect ltoCanOmit for symbols in non-prevailing COMDAT #119332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
8 changes: 3 additions & 5 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,6 @@ static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {
}

static void createBitcodeSymbol(Ctx &ctx, Symbol *&sym,
const std::vector<bool> &keptComdats,
const lto::InputFile::Symbol &objSym,
BitcodeFile &f) {
uint8_t binding = objSym.isWeak() ? STB_WEAK : STB_GLOBAL;
Expand All @@ -1726,8 +1725,7 @@ 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;
Expand Down Expand Up @@ -1766,10 +1764,10 @@ void BitcodeFile::parse() {
// ObjFile<ELFT>::initializeSymbols.
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
if (!irSym.isUndefined())
createBitcodeSymbol(ctx, symbols[i], keptComdats, irSym, *this);
createBitcodeSymbol(ctx, symbols[i], irSym, *this);
for (auto [i, irSym] : llvm::enumerate(obj->symbols()))
if (irSym.isUndefined())
createBitcodeSymbol(ctx, symbols[i], keptComdats, irSym, *this);
createBitcodeSymbol(ctx, symbols[i], irSym, *this);

for (auto l : obj->getDependentLibraries())
addDependentLibrary(ctx, l, this);
Expand Down
7 changes: 5 additions & 2 deletions lld/test/ELF/lto/internalize-exportdyn.ll
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ define linkonce_odr void @baz() {

@use_baz = global ptr @baz

;; Test comdat symbols that are prevailing in this module and non-prevailing in the other module.
define void @ext_and_ext() local_unnamed_addr comdat {
call void @foo(i64 1)
ret void
}

;; linkonce_odr in this module and external in the other module.
define linkonce_odr void @lo_and_ext() local_unnamed_addr comdat {
call void @foo(i64 1)
ret void
}

;; linkonce_odr in this module and weak_odr in the other module.
define linkonce_odr void @lo_and_wo() local_unnamed_addr comdat {
ret void
}
Expand All @@ -92,7 +95,7 @@ define weak_odr void @wo_and_lo() local_unnamed_addr comdat {
; CHECK-NEXT: call void @foo(i64 1)
; CHECK: define internal void @lo_and_ext() comdat
; CHECK-NEXT: call void @foo(i64 1)
; CHECK: define internal void @lo_and_wo() comdat
; CHECK: define weak_odr dso_local void @lo_and_wo() comdat
; CHECK: define weak_odr dso_local void @wo_and_lo() comdat

; DSO: @c = weak_odr constant i32 1
Expand All @@ -110,7 +113,7 @@ define weak_odr void @wo_and_lo() local_unnamed_addr comdat {
; DSO: define weak_odr void @baz()
; DSO: define void @ext_and_ext() comdat
; DSO: define internal void @lo_and_ext() comdat
; DSO: define internal void @lo_and_wo() comdat
; DSO: define weak_odr void @lo_and_wo() comdat
; DSO: define weak_odr void @wo_and_lo() comdat

;--- lib.s
Expand Down
Loading