- cast<ArrayType>(TypeMap.get(SrcGV->getType()->getElementType()));
- Type *EltTy = DstTy->getElementType();
-
- // Check to see that they two arrays agree on type.
- if (EltTy != SrcTy->getElementType())
- return emitError("Appending variables with different element types!");
- if (DstGV->isConstant() != SrcGV->isConstant())
- return emitError("Appending variables linked with different const'ness!");
-
- if (DstGV->getAlignment() != SrcGV->getAlignment())
- return emitError(
- "Appending variables with different alignment need to be linked!");
-
- if (DstGV->getVisibility() != SrcGV->getVisibility())
- return emitError(
- "Appending variables with different visibility need to be linked!");
-
- if (DstGV->hasUnnamedAddr() != SrcGV->hasUnnamedAddr())
- return emitError(
- "Appending variables with different unnamed_addr need to be linked!");
-
- if (StringRef(DstGV->getSection()) != SrcGV->getSection())
- return emitError(
+ cast<ArrayType>(TypeMap.get(SrcGV->getType()->getElementType()));
+ Type *EltTy = SrcTy->getElementType();
+
+ uint64_t NewSize = SrcTy->getNumElements();
+ if (DstGV) {
+ ArrayType *DstTy = cast<ArrayType>(DstGV->getType()->getElementType());
+ NewSize += DstTy->getNumElements();
+
+ if (!SrcGV->hasAppendingLinkage() || !DstGV->hasAppendingLinkage())
+ return emitError(
+ "Linking globals named '" + SrcGV->getName() +
+ "': can only link appending global with another appending global!");
+
+ // Check to see that they two arrays agree on type.
+ if (EltTy != DstTy->getElementType())
+ return emitError("Appending variables with different element types!");
+ if (DstGV->isConstant() != SrcGV->isConstant())
+ return emitError("Appending variables linked with different const'ness!");
+
+ if (DstGV->getAlignment() != SrcGV->getAlignment())
+ return emitError(
+ "Appending variables with different alignment need to be linked!");
+
+ if (DstGV->getVisibility() != SrcGV->getVisibility())
+ return emitError(
+ "Appending variables with different visibility need to be linked!");
+
+ if (DstGV->hasUnnamedAddr() != SrcGV->hasUnnamedAddr())
+ return emitError(
+ "Appending variables with different unnamed_addr need to be linked!");
+
+ if (StringRef(DstGV->getSection()) != SrcGV->getSection())
+ return emitError(