1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 10:32:48 +02:00

[IR] Rename comdat noduplicates to comdat nodeduplicate

In the textual format, `noduplicates` means no COMDAT/section group
deduplication is performed. Therefore, if both sets of sections are retained, and
they happen to define strong external symbols with the same names,
there will be a duplicate definition linker error.

In PE/COFF, the selection kind lowers to `IMAGE_COMDAT_SELECT_NODUPLICATES`.
The name describes the corollary instead of the immediate semantics.  The name
can cause confusion to other binary formats (ELF, wasm) which have implemented/
want to implement the "no deduplication" selection kind. Rename it to be clearer.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D106319
This commit is contained in:
Fangrui Song 2021-07-20 12:47:10 -07:00
parent 0d5ca9b780
commit dd6e19a41c
39 changed files with 78 additions and 79 deletions

View File

@ -290,7 +290,7 @@ const (
AnyComdatSelectionKind ComdatSelectionKind = C.LLVMAnyComdatSelectionKind
ExactMatchComdatSelectionKind ComdatSelectionKind = C.LLVMExactMatchComdatSelectionKind
LargestComdatSelectionKind ComdatSelectionKind = C.LLVMLargestComdatSelectionKind
NoDuplicatesComdatSelectionKind ComdatSelectionKind = C.LLVMNoDuplicatesComdatSelectionKind
NoDeduplicateComdatSelectionKind ComdatSelectionKind = C.LLVMNoDeduplicateComdatSelectionKind
SameSizeComdatSelectionKind ComdatSelectionKind = C.LLVMSameSizeComdatSelectionKind
)

View File

@ -1013,7 +1013,7 @@ The integer codes are mapped to well-known attributes as follows.
* code 9: ``noalias``
* code 10: ``nobuiltin``
* code 11: ``nocapture``
* code 12: ``noduplicates``
* code 12: ``nodeduplicate``
* code 13: ``noimplicitfloat``
* code 14: ``noinline``
* code 15: ``nonlazybind``

View File

@ -938,8 +938,8 @@ The selection kind must be one of the following:
same data.
``largest``
The linker will choose the section containing the largest COMDAT key.
``noduplicates``
The linker requires that only section with this COMDAT key exist.
``nodeduplicate``
No deduplication is performed.
``samesize``
The linker may choose any COMDAT key but the sections must contain the
same amount of data.

View File

@ -25,8 +25,7 @@ typedef enum {
///< be the same.
LLVMLargestComdatSelectionKind, ///< The linker will choose the largest
///< COMDAT.
LLVMNoDuplicatesComdatSelectionKind, ///< No other Module may specify this
///< COMDAT.
LLVMNoDeduplicateComdatSelectionKind, ///< No deduplication is performed.
LLVMSameSizeComdatSelectionKind ///< The data referenced by the COMDAT must be
///< the same size.
} LLVMComdatSelectionKind;

View File

@ -261,7 +261,7 @@ enum Kind {
kw_any,
kw_exactmatch,
kw_largest,
kw_noduplicates,
kw_nodeduplicate,
kw_samesize,
kw_eq,

View File

@ -31,11 +31,11 @@ template <typename ValueTy> class StringMapEntry;
class Comdat {
public:
enum SelectionKind {
Any, ///< The linker may choose any COMDAT.
ExactMatch, ///< The data referenced by the COMDAT must be the same.
Largest, ///< The linker will choose the largest COMDAT.
NoDuplicates, ///< No other Module may specify this COMDAT.
SameSize, ///< The data referenced by the COMDAT must be the same size.
Any, ///< The linker may choose any COMDAT.
ExactMatch, ///< The data referenced by the COMDAT must be the same.
Largest, ///< The linker will choose the largest COMDAT.
NoDeduplicate, ///< No deduplication is performed.
SameSize, ///< The data referenced by the COMDAT must be the same size.
};
Comdat(const Comdat &) = delete;

View File

@ -717,7 +717,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(any);
KEYWORD(exactmatch);
KEYWORD(largest);
KEYWORD(noduplicates);
KEYWORD(nodeduplicate);
KEYWORD(samesize);
KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);

View File

@ -668,8 +668,8 @@ bool LLParser::parseComdat() {
case lltok::kw_largest:
SK = Comdat::Largest;
break;
case lltok::kw_noduplicates:
SK = Comdat::NoDuplicates;
case lltok::kw_nodeduplicate:
SK = Comdat::NoDeduplicate;
break;
case lltok::kw_samesize:
SK = Comdat::SameSize;

View File

@ -1128,7 +1128,7 @@ static Comdat::SelectionKind getDecodedComdatSelectionKind(unsigned Val) {
case bitc::COMDAT_SELECTION_KIND_LARGEST:
return Comdat::Largest;
case bitc::COMDAT_SELECTION_KIND_NO_DUPLICATES:
return Comdat::NoDuplicates;
return Comdat::NoDeduplicate;
case bitc::COMDAT_SELECTION_KIND_SAME_SIZE:
return Comdat::SameSize;
}

View File

@ -1132,7 +1132,7 @@ static unsigned getEncodedComdatSelectionKind(const Comdat &C) {
return bitc::COMDAT_SELECTION_KIND_EXACT_MATCH;
case Comdat::Largest:
return bitc::COMDAT_SELECTION_KIND_LARGEST;
case Comdat::NoDuplicates:
case Comdat::NoDeduplicate:
return bitc::COMDAT_SELECTION_KIND_NO_DUPLICATES;
case Comdat::SameSize:
return bitc::COMDAT_SELECTION_KIND_SAME_SIZE;

View File

@ -532,10 +532,10 @@ static const Comdat *getELFComdat(const GlobalValue *GV) {
return nullptr;
if (C->getSelectionKind() != Comdat::Any &&
C->getSelectionKind() != Comdat::NoDuplicates)
C->getSelectionKind() != Comdat::NoDeduplicate)
report_fatal_error("ELF COMDATs only support SelectionKind::Any and "
"SelectionKind::NoDuplicates, '" + C->getName() +
"' cannot be lowered.");
"SelectionKind::NoDeduplicate, '" +
C->getName() + "' cannot be lowered.");
return C;
}
@ -1571,7 +1571,7 @@ static int getSelectionForCOFF(const GlobalValue *GV) {
return COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH;
case Comdat::Largest:
return COFF::IMAGE_COMDAT_SELECT_LARGEST;
case Comdat::NoDuplicates:
case Comdat::NoDeduplicate:
return COFF::IMAGE_COMDAT_SELECT_NODUPLICATES;
case Comdat::SameSize:
return COFF::IMAGE_COMDAT_SELECT_SAME_SIZE;

View File

@ -4554,8 +4554,8 @@ void Comdat::print(raw_ostream &ROS, bool /*IsForDebug*/) const {
case Comdat::Largest:
ROS << "largest";
break;
case Comdat::NoDuplicates:
ROS << "noduplicates";
case Comdat::NoDeduplicate:
ROS << "nodeduplicate";
break;
case Comdat::SameSize:
ROS << "samesize";

View File

@ -47,8 +47,8 @@ LLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C) {
return LLVMExactMatchComdatSelectionKind;
case Comdat::Largest:
return LLVMLargestComdatSelectionKind;
case Comdat::NoDuplicates:
return LLVMNoDuplicatesComdatSelectionKind;
case Comdat::NoDeduplicate:
return LLVMNoDeduplicateComdatSelectionKind;
case Comdat::SameSize:
return LLVMSameSizeComdatSelectionKind;
}
@ -67,8 +67,8 @@ void LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind kind) {
case LLVMLargestComdatSelectionKind:
Cd->setSelectionKind(Comdat::Largest);
break;
case LLVMNoDuplicatesComdatSelectionKind:
Cd->setSelectionKind(Comdat::NoDuplicates);
case LLVMNoDeduplicateComdatSelectionKind:
Cd->setSelectionKind(Comdat::NoDeduplicate);
break;
case LLVMSameSizeComdatSelectionKind:
Cd->setSelectionKind(Comdat::SameSize);

View File

@ -177,9 +177,9 @@ bool ModuleLinker::computeResultingSelectionKind(StringRef ComdatName,
// Go with Dst.
LinkFromSrc = false;
break;
case Comdat::SelectionKind::NoDuplicates:
case Comdat::SelectionKind::NoDeduplicate:
return emitError("Linking COMDATs named '" + ComdatName +
"': noduplicates has been violated!");
"': nodeduplicate has been violated!");
case Comdat::SelectionKind::ExactMatch:
case Comdat::SelectionKind::Largest:
case Comdat::SelectionKind::SameSize: {

View File

@ -131,14 +131,14 @@ bool InternalizePass::maybeInternalize(
// If a comdat with one member is not externally visible, we can drop it.
// Otherwise, the comdat can be used to establish dependencies among the
// group of sections. Thus we have to keep the comdat but switch it to
// noduplicates.
// Note: noduplicates is not necessary for COFF. wasm doesn't support
// noduplicates.
// nodeduplicate.
// Note: nodeduplicate is not necessary for COFF. wasm doesn't support
// nodeduplicate.
ComdatInfo &Info = ComdatMap.find(C)->second;
if (Info.Size == 1)
GO->setComdat(nullptr);
else if (!IsWasm)
C->setSelectionKind(Comdat::NoDuplicates);
C->setSelectionKind(Comdat::NoDeduplicate);
}
if (GV.hasLocalLinkage())

View File

@ -1919,7 +1919,7 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
switch (C->getSelectionKind()) {
case Comdat::Any:
case Comdat::ExactMatch:
case Comdat::NoDuplicates:
case Comdat::NoDeduplicate:
break;
case Comdat::Largest:
case Comdat::SameSize:
@ -2106,7 +2106,7 @@ void ModuleAddressSanitizer::SetComdatForGlobalMetadata(
// linkage to internal linkage so that a symbol table entry is emitted. This
// is necessary in order to create the comdat group.
if (TargetTriple.isOSBinFormatCOFF()) {
C->setSelectionKind(Comdat::NoDuplicates);
C->setSelectionKind(Comdat::NoDeduplicate);
if (G->hasPrivateLinkage())
G->setLinkage(GlobalValue::InternalLinkage);
}

View File

@ -862,7 +862,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
// same name marked IMAGE_COMDAT_SELECT_ASSOCIATIVE.
//
// For ELF, when not using COMDAT, put counters, data and values into a
// noduplicates COMDAT which is lowered to a zero-flag section group. This
// nodeduplicate COMDAT which is lowered to a zero-flag section group. This
// allows -z start-stop-gc to discard the entire group when the function is
// discarded.
bool DataReferencedByCode = profDataReferencedByCode(*M);
@ -877,7 +877,7 @@ InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
: CntsVarName;
Comdat *C = M->getOrInsertComdat(GroupName);
if (!NeedComdat)
C->setSelectionKind(Comdat::NoDuplicates);
C->setSelectionKind(Comdat::NoDeduplicate);
GV->setComdat(C);
}
};

View File

@ -83,7 +83,7 @@ Comdat *llvm::getOrCreateFunctionComdat(Function &F, Triple &T) {
// symbols.
Comdat *C = M->getOrInsertComdat(F.getName());
if (T.isOSBinFormatELF() || (T.isOSBinFormatCOFF() && !F.isWeakForLinker()))
C->setSelectionKind(Comdat::NoDuplicates);
C->setSelectionKind(Comdat::NoDeduplicate);
F.setComdat(C);
return C;
}

View File

@ -23,8 +23,8 @@ $comdat.exactmatch = comdat exactmatch
; CHECK: $comdat.exactmatch = comdat exactmatch
$comdat.largest = comdat largest
; CHECK: $comdat.largest = comdat largest
$comdat.noduplicates = comdat noduplicates
; CHECK: $comdat.noduplicates = comdat noduplicates
$comdat.noduplicates = comdat nodeduplicate
; CHECK: $comdat.noduplicates = comdat nodeduplicate
$comdat.samesize = comdat samesize
; CHECK: $comdat.samesize = comdat samesize

View File

@ -23,8 +23,8 @@ $comdat.exactmatch = comdat exactmatch
; CHECK: $comdat.exactmatch = comdat exactmatch
$comdat.largest = comdat largest
; CHECK: $comdat.largest = comdat largest
$comdat.noduplicates = comdat noduplicates
; CHECK: $comdat.noduplicates = comdat noduplicates
$comdat.noduplicates = comdat nodeduplicate
; CHECK: $comdat.noduplicates = comdat nodeduplicate
$comdat.samesize = comdat samesize
; CHECK: $comdat.samesize = comdat samesize

View File

@ -22,8 +22,8 @@ $comdat.exactmatch = comdat exactmatch
; CHECK: $comdat.exactmatch = comdat exactmatch
$comdat.largest = comdat largest
; CHECK: $comdat.largest = comdat largest
$comdat.noduplicates = comdat noduplicates
; CHECK: $comdat.noduplicates = comdat noduplicates
$comdat.noduplicates = comdat nodeduplicate
; CHECK: $comdat.noduplicates = comdat nodeduplicate
$comdat.samesize = comdat samesize
; CHECK: $comdat.samesize = comdat samesize

View File

@ -22,8 +22,8 @@ $comdat.exactmatch = comdat exactmatch
; CHECK: $comdat.exactmatch = comdat exactmatch
$comdat.largest = comdat largest
; CHECK: $comdat.largest = comdat largest
$comdat.noduplicates = comdat noduplicates
; CHECK: $comdat.noduplicates = comdat noduplicates
$comdat.noduplicates = comdat nodeduplicate
; CHECK: $comdat.noduplicates = comdat nodeduplicate
$comdat.samesize = comdat samesize
; CHECK: $comdat.samesize = comdat samesize

View File

@ -22,8 +22,8 @@ $comdat.exactmatch = comdat exactmatch
; CHECK: $comdat.exactmatch = comdat exactmatch
$comdat.largest = comdat largest
; CHECK: $comdat.largest = comdat largest
$comdat.noduplicates = comdat noduplicates
; CHECK: $comdat.noduplicates = comdat noduplicates
$comdat.noduplicates = comdat nodeduplicate
; CHECK: $comdat.noduplicates = comdat nodeduplicate
$comdat.samesize = comdat samesize
; CHECK: $comdat.samesize = comdat samesize

View File

@ -22,8 +22,8 @@ $comdat.exactmatch = comdat exactmatch
; CHECK: $comdat.exactmatch = comdat exactmatch
$comdat.largest = comdat largest
; CHECK: $comdat.largest = comdat largest
$comdat.noduplicates = comdat noduplicates
; CHECK: $comdat.noduplicates = comdat noduplicates
$comdat.noduplicates = comdat nodeduplicate
; CHECK: $comdat.noduplicates = comdat nodeduplicate
$comdat.samesize = comdat samesize
; CHECK: $comdat.samesize = comdat samesize

View File

@ -23,8 +23,8 @@ $comdat.exactmatch = comdat exactmatch
; CHECK: $comdat.exactmatch = comdat exactmatch
$comdat.largest = comdat largest
; CHECK: $comdat.largest = comdat largest
$comdat.noduplicates = comdat noduplicates
; CHECK: $comdat.noduplicates = comdat noduplicates
$comdat.noduplicates = comdat nodeduplicate
; CHECK: $comdat.noduplicates = comdat nodeduplicate
$comdat.samesize = comdat samesize
; CHECK: $comdat.samesize = comdat samesize

View File

@ -25,8 +25,8 @@ $comdat.exactmatch = comdat exactmatch
; CHECK: $comdat.exactmatch = comdat exactmatch
$comdat.largest = comdat largest
; CHECK: $comdat.largest = comdat largest
$comdat.noduplicates = comdat noduplicates
; CHECK: $comdat.noduplicates = comdat noduplicates
$comdat.noduplicates = comdat nodeduplicate
; CHECK: $comdat.noduplicates = comdat nodeduplicate
$comdat.samesize = comdat samesize
; CHECK: $comdat.samesize = comdat samesize

View File

@ -18,7 +18,7 @@ define void @f3() comdat($f3) {
ret void
}
$f4 = comdat noduplicates
$f4 = comdat nodeduplicate
@v4 = global i32 0, comdat($f4)
define void @f4() comdat($f4) {
ret void

View File

@ -1,4 +1,4 @@
; Checks that comdat with noduplicates kind is lowered to a zero-flag ELF
; Checks that comdat with nodeduplicate kind is lowered to a zero-flag ELF
; section group.
; RUN: llc < %s -mtriple=x86_64-unknown-linux | FileCheck %s
@ -6,7 +6,7 @@
; CHECK: .section .text.f2,"axG",@progbits,f1{{$}}
; CHECK: .section .bss.g1,"aGw",@nobits,f1{{$}}
$f1 = comdat noduplicates
$f1 = comdat nodeduplicate
define void @f1() comdat {
unreachable

View File

@ -53,9 +53,9 @@ eh.resume:
resume { i8*, i32 } %0
}
;; If the function is in a comdat group with noduplicates kind, the generated
;; If the function is in a comdat group with nodeduplicate kind, the generated
;; .gcc_except_table should is lowered to a zero-flag ELF section group.
$zero = comdat noduplicates
$zero = comdat nodeduplicate
define i32 @zero() uwtable comdat personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: zero:
; CHECK: .cfi_endproc

View File

@ -12,8 +12,8 @@ target triple = "x86_64-pc-windows-msvc19.0.24215"
$mystr = comdat any
; CHECK: $dead_global = comdat noduplicates
; CHECK: $private_str = comdat noduplicates
; CHECK: $dead_global = comdat nodeduplicate
; CHECK: $private_str = comdat nodeduplicate
; CHECK: @dead_global = global { i32, [28 x i8] } { i32 42, [28 x i8] zeroinitializer }, comdat, align 32
; CHECK: @private_str = internal constant { [8 x i8], [24 x i8] } { [8 x i8] c"private\00", [24 x i8] zeroinitializer }, comdat, align 32

View File

@ -12,10 +12,10 @@
; MACHO: @__llvm_profile_runtime = external global i32
; ELF-NOT: @__llvm_profile_runtime = external global i32
; ELF: $__profc_foo = comdat noduplicates
; ELF: $__profc_foo_weak = comdat noduplicates
; ELF: $"__profc_linkage.ll:foo_internal" = comdat noduplicates
; ELF: $__profc_foo_inline = comdat noduplicates
; ELF: $__profc_foo = comdat nodeduplicate
; ELF: $__profc_foo_weak = comdat nodeduplicate
; ELF: $"__profc_linkage.ll:foo_internal" = comdat nodeduplicate
; ELF: $__profc_foo_inline = comdat nodeduplicate
; ELF: $__profc_foo_extern = comdat any
@__profn_foo = private constant [3 x i8] c"foo"

View File

@ -20,8 +20,8 @@
; Both new comdats should no duplicates on COFF.
; CHECK: $foo = comdat noduplicates
; CHECK: $bar = comdat noduplicates
; CHECK: $foo = comdat nodeduplicate
; CHECK: $bar = comdat nodeduplicate
; Tables for 'foo' should be in the 'foo' comdat.

View File

@ -2,7 +2,7 @@
; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-inline-bool-flag=1 -S -enable-new-pm=0 | FileCheck %s
; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-inline-bool-flag=1 -S | FileCheck %s
; CHECK: $foo = comdat noduplicates
; CHECK: $foo = comdat nodeduplicate
; CHECK: @__sancov_gen_ = private global [1 x i1] zeroinitializer, section "__sancov_bools", comdat($foo), align 1{{$}}
; CHECK: @__start___sancov_bools = extern_weak hidden global i1
; CHECK-NEXT: @__stop___sancov_bools = extern_weak hidden global i1

View File

@ -31,8 +31,8 @@ entry:
ret void
}
; CHECK: $Vanilla = comdat noduplicates
; ELF: $LinkOnceOdr = comdat noduplicates
; CHECK: $Vanilla = comdat nodeduplicate
; ELF: $LinkOnceOdr = comdat nodeduplicate
; COFF: $LinkOnceOdr = comdat any
; CHECK: @__sancov_gen_ = private global [1 x i32] zeroinitializer, section {{.*}}, comdat($Vanilla), align 4{{$}}
; CHECK-NEXT: @__sancov_gen_.1 = private global [1 x i32] zeroinitializer, section {{.*}}, align 4{{$}}

View File

@ -6,8 +6,8 @@
; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=4 -sanitizer-coverage-trace-pc-guard -mtriple=x86_64-windows -S | FileCheck %s --check-prefixes=CHECK,COMDAT,WIN
; COMDAT: $foo = comdat noduplicates
; COMDAT: $CallViaVptr = comdat noduplicates
; COMDAT: $foo = comdat nodeduplicate
; COMDAT: $CallViaVptr = comdat nodeduplicate
; ELF: @__sancov_gen_ = private global [3 x i32] zeroinitializer, section "__sancov_guards", comdat($foo), align 4{{$}}
; ELF-NEXT: @__sancov_gen_.1 = private global [1 x i32] zeroinitializer, section "__sancov_guards", comdat($CallViaVptr), align 4{{$}}

View File

@ -1,2 +1,2 @@
$foo = comdat noduplicates
$foo = comdat nodeduplicate
@foo = global i64 43, comdat($foo)

View File

@ -1,5 +1,5 @@
; RUN: not llvm-link %s %p/Inputs/comdat3.ll -S -o - 2>&1 | FileCheck %s
$foo = comdat noduplicates
$foo = comdat nodeduplicate
@foo = global i64 43, comdat($foo)
; CHECK: Linking COMDATs named 'foo': noduplicates has been violated!
; CHECK: Linking COMDATs named 'foo': nodeduplicate has been violated!

View File

@ -45,13 +45,13 @@ entry:
$source_comdat_variable = comdat largest
@source_comdat_variable = global i32 32, comdat($source_comdat_variable)
$source_comdat_variable_1 = comdat noduplicates
$source_comdat_variable_1 = comdat nodeduplicate
@source_comdat_variable_1 = global i32 64, comdat($source_comdat_variable_1)
; CHECK: $target_comdat_function = comdat any
; CHECK: $target_comdat_function_1 = comdat exactmatch
; CHECK: $target_comdat_variable = comdat largest
; CHECK: $target_comdat_variable_1 = comdat noduplicates
; CHECK: $target_comdat_variable_1 = comdat nodeduplicate
; CHECK: @target_variable = external global i32
; CHECK-NOT: @source_variable = external global i32

View File

@ -13,8 +13,8 @@ $c5 = comdat any
; CHECK: $c1 = comdat any
;; wasm doesn't support noduplicates.
; NODUP: $c2 = comdat noduplicates
;; wasm doesn't support nodeduplicate.
; NODUP: $c2 = comdat nodeduplicate
; WASM: $c2 = comdat any
; CHECK: $c3 = comdat any