mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-08 05:16:53 +00:00
Fix pr20078.
When linking llvm.global_ctors with the optional third element we have to handle it specially and only copy the elements whose keys were also copied. llvm-svn: 217281
This commit is contained in:
parent
a2eead0028
commit
f6f642b911
@ -1223,14 +1223,34 @@ static void getArrayElements(Constant *C, SmallVectorImpl<Constant*> &Dest) {
|
|||||||
|
|
||||||
void ModuleLinker::linkAppendingVarInit(const AppendingVarInfo &AVI) {
|
void ModuleLinker::linkAppendingVarInit(const AppendingVarInfo &AVI) {
|
||||||
// Merge the initializer.
|
// Merge the initializer.
|
||||||
SmallVector<Constant*, 16> Elements;
|
SmallVector<Constant *, 16> DstElements;
|
||||||
getArrayElements(AVI.DstInit, Elements);
|
getArrayElements(AVI.DstInit, DstElements);
|
||||||
|
|
||||||
Constant *SrcInit = MapValue(AVI.SrcInit, ValueMap, RF_None, &TypeMap, &ValMaterializer);
|
SmallVector<Constant *, 16> SrcElements;
|
||||||
getArrayElements(SrcInit, Elements);
|
getArrayElements(AVI.SrcInit, SrcElements);
|
||||||
|
|
||||||
ArrayType *NewType = cast<ArrayType>(AVI.NewGV->getType()->getElementType());
|
ArrayType *NewType = cast<ArrayType>(AVI.NewGV->getType()->getElementType());
|
||||||
AVI.NewGV->setInitializer(ConstantArray::get(NewType, Elements));
|
|
||||||
|
StringRef Name = AVI.NewGV->getName();
|
||||||
|
bool IsNewStructor =
|
||||||
|
(Name == "llvm.global_ctors" || Name == "llvm.global_dtors") &&
|
||||||
|
cast<StructType>(NewType->getElementType())->getNumElements() == 3;
|
||||||
|
|
||||||
|
for (auto *V : SrcElements) {
|
||||||
|
if (IsNewStructor) {
|
||||||
|
Constant *Key = V->getAggregateElement(2);
|
||||||
|
if (DoNotLinkFromSource.count(Key))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DstElements.push_back(
|
||||||
|
MapValue(V, ValueMap, RF_None, &TypeMap, &ValMaterializer));
|
||||||
|
}
|
||||||
|
if (IsNewStructor) {
|
||||||
|
NewType = ArrayType::get(NewType->getElementType(), DstElements.size());
|
||||||
|
AVI.NewGV->mutateType(PointerType::get(NewType, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
AVI.NewGV->setInitializer(ConstantArray::get(NewType, DstElements));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// linkGlobalInits - Update the initializers in the Dest module now that all
|
/// linkGlobalInits - Update the initializers in the Dest module now that all
|
||||||
|
6
test/Linker/Inputs/ctors.ll
Normal file
6
test/Linker/Inputs/ctors.ll
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
@v = weak global i8 1
|
||||||
|
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* @v}]
|
||||||
|
|
||||||
|
define weak void @f() {
|
||||||
|
ret void
|
||||||
|
}
|
15
test/Linker/ctors.ll
Normal file
15
test/Linker/ctors.ll
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
; RUN: llvm-link %s %p/Inputs/ctors.ll -S -o - | \
|
||||||
|
; RUN: FileCheck --check-prefix=ALL --check-prefix=CHECK1 %s
|
||||||
|
; RUN: llvm-link %p/Inputs/ctors.ll %s -S -o - | \
|
||||||
|
; RUN: FileCheck --check-prefix=ALL --check-prefix=CHECK2 %s
|
||||||
|
|
||||||
|
@v = weak global i8 0
|
||||||
|
; CHECK1: @v = weak global i8 0
|
||||||
|
; CHECK2: @v = weak global i8 1
|
||||||
|
|
||||||
|
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* @v }]
|
||||||
|
; ALL: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* @v }]
|
||||||
|
|
||||||
|
define weak void @f() {
|
||||||
|
ret void
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user