Skip to content

[lld][ELF] Resolve Symbols with same comdat index as Defined Symbols #115140

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

Closed
wants to merge 2 commits into from
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 @@ -1726,13 +1726,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);
sym->ltoCanOmit = objSym.canBeOmittedFromSymbolTable() &&
(!sym->isDefined() || sym->ltoCanOmit);
sym->resolve(ctx, newSym);
return;
}

if (objSym.isCommon()) {
sym->resolve(ctx, CommonSymbol{ctx, &f, StringRef(), binding, visibility,
Expand Down
10 changes: 10 additions & 0 deletions lld/test/ELF/lto/Inputs/internalize-exportdyn.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
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"

$f1 = comdat any
$f2 = comdat any

define weak_odr void @bah() {
ret void
}

define linkonce_odr void @f1() local_unnamed_addr comdat {
ret void
}
define weak_odr void @f2() local_unnamed_addr comdat {
ret void
}
15 changes: 15 additions & 0 deletions lld/test/ELF/lto/internalize-exportdyn.ll
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
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"

$f1 = comdat any
$f2 = comdat any

@c = linkonce_odr constant i32 1
@g = linkonce_odr global i32 1
@u_c = linkonce_odr unnamed_addr constant i32 1
Expand Down Expand Up @@ -46,6 +49,14 @@ define linkonce_odr void @baz() {

@use_baz = global ptr @baz

define weak_odr void @f1() local_unnamed_addr comdat {
ret void
}

define linkonce_odr void @f2() local_unnamed_addr comdat {
ret void
}

; Check what gets internalized.
; CHECK: @c = weak_odr dso_local constant i32 1
; CHECK: @g = weak_odr dso_local global i32 1
Expand All @@ -60,6 +71,8 @@ define linkonce_odr void @baz() {
; CHECK: define internal void @zed2()
; CHECK: define weak_odr dso_local void @bah()
; CHECK: define weak_odr dso_local void @baz()
; CHECK: define weak_odr dso_local void @f1() comdat
; CHECK: define weak_odr dso_local void @f2() comdat

; DSO: @c = weak_odr constant i32 1
; DSO: @g = weak_odr global i32 1
Expand All @@ -74,3 +87,5 @@ define linkonce_odr void @baz() {
; DSO: define internal void @zed2()
; DSO: define weak_odr void @bah()
; DSO: define weak_odr void @baz()
; DSO: define weak_odr void @f1() comdat
; DSO: define weak_odr void @f2() comdat
Loading