Skip to content

Commit e6ebf51

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merge upstream LLVM into amd-gfx12
2 parents 757ad43 + 3813567 commit e6ebf51

File tree

14 files changed

+162
-76
lines changed

14 files changed

+162
-76
lines changed

lld/test/MachO/objc.s

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/has-swift.s -o %t/has-swift.o
88
# RUN: llvm-as %t/has-swift-ir-loaded.ll -o %t/has-swift-ir-loaded.o
99
# RUN: llvm-as %t/has-swift-ir-not-loaded.ll -o %t/has-swift-ir-not-loaded.o
10+
# RUN: llvm-as %t/has-swift-with-space-ir-loaded.ll -o %t/has-swift-with-space-ir-loaded.o
1011
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/has-swift-proto.s -o %t/has-swift-proto.o
1112
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/no-objc.s -o %t/no-objc.o
1213
## Make sure we don't mis-parse a 32-bit file as 64-bit
1314
# RUN: llvm-mc -filetype=obj -triple=armv7-apple-watchos %t/no-objc.s -o %t/wrong-arch.o
14-
# RUN: llvm-ar rcs %t/libHasSomeObjC.a %t/no-objc.o %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/wrong-arch.o
15-
# RUN: llvm-ar rcs %t/libHasSomeObjC2.a %t/no-objc.o %t/has-objc-symbol-and-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/wrong-arch.o
15+
# RUN: llvm-ar rcs %t/libHasSomeObjC.a %t/no-objc.o %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/has-swift-with-space-ir-loaded.o %t/wrong-arch.o
16+
# RUN: llvm-ar rcs %t/libHasSomeObjC2.a %t/no-objc.o %t/has-objc-symbol-and-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/has-swift-with-space-ir-loaded.o %t/wrong-arch.o
1617

1718
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
1819

@@ -22,7 +23,7 @@
2223
# RUN: %lld -lSystem %t/test.o -o %t/test -L%t -lHasSomeObjC2 -ObjC
2324
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC
2425

25-
# RUN: %no-fatal-warnings-lld -lSystem %t/test.o -o %t/test --start-lib %t/no-objc.o %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/wrong-arch.o --end-lib -ObjC 2>&1 \
26+
# RUN: %no-fatal-warnings-lld -lSystem %t/test.o -o %t/test --start-lib %t/no-objc.o %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/has-swift-proto.o %t/has-swift-ir-loaded.o %t/has-swift-ir-not-loaded.o %t/has-swift-with-space-ir-loaded.o %t/wrong-arch.o --end-lib -ObjC 2>&1 \
2627
# RUN: | FileCheck -check-prefix=WARNING %s
2728
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC
2829

@@ -34,14 +35,16 @@
3435
# OBJC-NEXT: 0 __text {{.*}} TEXT
3536
# OBJC-NEXT: 1 __swift {{.*}} DATA
3637
# OBJC-NEXT: 2 __swift5_fieldmd{{.*}} DATA
37-
# OBJC-NEXT: 3 __objc_catlist {{.*}} DATA
38-
# OBJC-NEXT: 4 has_objc_symbol {{.*}} DATA
38+
# OBJC-NEXT: 3 __swift5_proto {{.*}} DATA
39+
# OBJC-NEXT: 4 __objc_catlist {{.*}} DATA
40+
# OBJC-NEXT: 5 has_objc_symbol {{.*}} DATA
3941
# OBJC-EMPTY:
4042
# OBJC-NEXT: SYMBOL TABLE:
4143
# OBJC-DAG: g O __TEXT,__swift _foo
4244
# OBJC-DAG: g F __TEXT,__text _main
4345
# OBJC-DAG: g F __TEXT,__text _OBJC_CLASS_$_MyObject
4446
# OBJC-DAG: g O __TEXT,__swift5_fieldmd $s7somelib4Blah_pMF
47+
# OBJC-DAG: g O __TEXT,__swift5_proto _baz
4548

4649
# RUN: %lld -lSystem %t/test.o -o %t/test -L%t -lHasSomeObjC
4750
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=NO-OBJC
@@ -117,6 +120,13 @@ target triple = "x86_64-apple-darwin"
117120
@bar = global i64 1234
118121
@llvm.used = appending global [1 x ptr] [ptr @bar]
119122

123+
#--- has-swift-with-space-ir-loaded.ll
124+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
125+
target triple = "x86_64-apple-darwin"
126+
127+
@baz = global i64 1234, section "__TEXT, __swift5_proto"
128+
@llvm.used = appending global [1 x ptr] [ptr @baz]
129+
120130
#--- has-swift-proto.s
121131
.section __TEXT,__swift5_fieldmd
122132
.globl $s7somelib4Blah_pMF

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ class MCObjectStreamer : public MCStreamer {
8383
// Add a fragment with a variable-size tail and start a new empty fragment.
8484
void insert(MCFragment *F);
8585

86-
void addFixup(const MCExpr *Value, MCFixupKind Kind, uint32_t Offset = 0);
8786
// Add a new fragment to the current section without a variable-size tail.
8887
void newFragment();
8988

89+
void appendContents(size_t Num, char Elt);
90+
void addFixup(const MCExpr *Value, MCFixupKind Kind);
91+
9092
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
9193
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment &F,
9294
uint64_t Offset);

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ class LLVM_ABI MCStreamer {
438438
assert(!CurFrag || CurFrag->getKind() == MCFragment::FT_Data);
439439
return CurFrag;
440440
}
441+
size_t getCurFragOffset() const { return getCurrentFragment()->Offset; }
441442
/// Save the current and previous section on the section stack.
442443
void pushSection() {
443444
SectionStack.push_back(

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,18 @@ static Expected<bool> hasObjCCategoryInModule(BitstreamCursor &Stream) {
293293
std::string S;
294294
if (convertToString(Record, 0, S))
295295
return error("Invalid section name record");
296+
296297
// Check for the i386 and other (x86_64, ARM) conventions
297-
if (S.find("__DATA,__objc_catlist") != std::string::npos ||
298-
S.find("__OBJC,__category") != std::string::npos ||
299-
S.find("__TEXT,__swift") != std::string::npos)
298+
299+
auto [Segment, Section] = StringRef(S).split(",");
300+
Segment = Segment.trim();
301+
Section = Section.trim();
302+
303+
if (Segment == "__DATA" && Section.starts_with("__objc_catlist"))
304+
return true;
305+
if (Segment == "__OBJC" && Section.starts_with("__category"))
306+
return true;
307+
if (Segment == "__TEXT" && Section.starts_with("__swift"))
300308
return true;
301309
break;
302310
}

llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#include "llvm/MC/MCPseudoProbe.h"
1919
#include "llvm/MC/MCStreamer.h"
2020

21+
#ifndef NDEBUG
22+
#include "llvm/IR/Module.h"
23+
#include "llvm/Support/WithColor.h"
24+
#endif
25+
2126
using namespace llvm;
2227

2328
void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index,
@@ -35,6 +40,9 @@ void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index,
3540
uint64_t &CallerGuid = NameGuidMap[Name];
3641
if (!CallerGuid)
3742
CallerGuid = Function::getGUIDAssumingExternalLinkage(Name);
43+
#ifndef NDEBUG
44+
verifyGuidExistenceInDesc(CallerGuid, Name);
45+
#endif
3846
uint64_t CallerProbeId = PseudoProbeDwarfDiscriminator::extractProbeIndex(
3947
InlinedAt->getDiscriminator());
4048
ReversedInlineStack.emplace_back(CallerGuid, CallerProbeId);
@@ -51,4 +59,28 @@ void PseudoProbeHandler::emitPseudoProbe(uint64_t Guid, uint64_t Index,
5159
SmallVector<InlineSite, 8> InlineStack(llvm::reverse(ReversedInlineStack));
5260
Asm->OutStreamer->emitPseudoProbe(Guid, Index, Type, Attr, Discriminator,
5361
InlineStack, Asm->CurrentFnSym);
62+
#ifndef NDEBUG
63+
verifyGuidExistenceInDesc(
64+
Guid, DebugLoc ? DebugLoc->getSubprogramLinkageName() : "");
65+
#endif
66+
}
67+
68+
#ifndef NDEBUG
69+
void PseudoProbeHandler::verifyGuidExistenceInDesc(uint64_t Guid,
70+
StringRef FuncName) {
71+
NamedMDNode *Desc = Asm->MF->getFunction().getParent()->getNamedMetadata(
72+
PseudoProbeDescMetadataName);
73+
assert(Desc && "pseudo probe does not exist");
74+
75+
// Keep DescGuidSet up to date.
76+
for (size_t I = DescGuidSet.size(), E = Desc->getNumOperands(); I != E; ++I) {
77+
const auto *MD = cast<MDNode>(Desc->getOperand(I));
78+
auto *ID = mdconst::extract<ConstantInt>(MD->getOperand(0));
79+
DescGuidSet.insert(ID->getZExtValue());
80+
}
81+
82+
if (!DescGuidSet.contains(Guid))
83+
WithColor::warning() << "Guid:" << Guid << " Name:" << FuncName
84+
<< " does not exist in pseudo probe desc\n";
5485
}
86+
#endif

llvm/lib/CodeGen/AsmPrinter/PseudoProbePrinter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
#include "llvm/ADT/DenseMap.h"
1717

18+
#ifndef NDEBUG
19+
#include "llvm/ADT/DenseSet.h"
20+
#endif
21+
1822
namespace llvm {
1923

2024
class AsmPrinter;
@@ -26,6 +30,13 @@ class PseudoProbeHandler {
2630
// Name to GUID map, used as caching/memoization for speed.
2731
DenseMap<StringRef, uint64_t> NameGuidMap;
2832

33+
#ifndef NDEBUG
34+
// All GUID in llvm.pseudo_probe_desc.
35+
DenseSet<uint64_t> DescGuidSet;
36+
37+
void verifyGuidExistenceInDesc(uint64_t Guid, StringRef FuncName);
38+
#endif
39+
2940
public:
3041
PseudoProbeHandler(AsmPrinter *A) : Asm(A) {};
3142

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ void MCObjectStreamer::insert(MCFragment *F) {
5858
newFragment();
5959
}
6060

61-
void MCObjectStreamer::addFixup(const MCExpr *Value, MCFixupKind Kind,
62-
uint32_t Offset) {
63-
CurFrag->addFixup(
64-
MCFixup::create(CurFrag->getFixedSize() + Offset, Value, Kind));
61+
void MCObjectStreamer::appendContents(size_t Num, char Elt) {
62+
CurFrag->appendContents(Num, Elt);
63+
}
64+
65+
void MCObjectStreamer::addFixup(const MCExpr *Value, MCFixupKind Kind) {
66+
CurFrag->addFixup(MCFixup::create(CurFrag->getFixedSize(), Value, Kind));
6567
}
6668

6769
// As a compile-time optimization, avoid allocating and evaluating an MCExpr

llvm/lib/MC/MCWin64EH.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,13 @@ static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {
318318

319319
// Emit the epilog instructions.
320320
if (EnableUnwindV2) {
321-
MCFragment *DF = OS->getCurrentFragment();
322-
323321
bool IsLast = true;
324322
for (const auto &Epilog : llvm::reverse(info->EpilogMap)) {
325323
if (IsLast) {
326324
IsLast = false;
327325
uint8_t Flags = LastEpilogIsAtEnd ? 0x01 : 0;
328-
streamer.emitInt8(EpilogSize);
329-
streamer.emitInt8((Flags << 4) | Win64EH::UOP_Epilog);
326+
OS->emitInt8(EpilogSize);
327+
OS->emitInt8((Flags << 4) | Win64EH::UOP_Epilog);
330328

331329
if (LastEpilogIsAtEnd)
332330
continue;
@@ -337,9 +335,8 @@ static void EmitUnwindInfo(MCStreamer &streamer, WinEH::FrameInfo *info) {
337335
// layout has been completed.
338336
auto *MCE = MCUnwindV2EpilogTargetExpr::create(*info, Epilog.second,
339337
EpilogSize, context);
340-
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_2);
341-
DF->addFixup(Fixup);
342-
DF->appendContents(2, 0);
338+
OS->addFixup(MCE, FK_Data_2);
339+
OS->appendContents(2, 0);
343340
}
344341
}
345342
if (AddPaddingEpilogCode)

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -278,76 +278,58 @@ void MCWinCOFFStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) {
278278

279279
void MCWinCOFFStreamer::emitCOFFSectionIndex(const MCSymbol *Symbol) {
280280
visitUsedSymbol(*Symbol);
281-
MCFragment *DF = getCurrentFragment();
282281
const MCSymbolRefExpr *SRE = MCSymbolRefExpr::create(Symbol, getContext());
283-
MCFixup Fixup = MCFixup::create(DF->getContents().size(), SRE, FK_SecRel_2);
284-
DF->addFixup(Fixup);
285-
DF->appendContents(2, 0);
282+
addFixup(SRE, FK_SecRel_2);
283+
appendContents(2, 0);
286284
}
287285

288286
void MCWinCOFFStreamer::emitCOFFSecRel32(const MCSymbol *Symbol,
289287
uint64_t Offset) {
290288
visitUsedSymbol(*Symbol);
291-
MCFragment *DF = getCurrentFragment();
292289
// Create Symbol A for the relocation relative reference.
293290
const MCExpr *MCE = MCSymbolRefExpr::create(Symbol, getContext());
294291
// Add the constant offset, if given.
295292
if (Offset)
296293
MCE = MCBinaryExpr::createAdd(
297294
MCE, MCConstantExpr::create(Offset, getContext()), getContext());
298-
// Build the secrel32 relocation.
299-
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_SecRel_4);
300-
// Record the relocation.
301-
DF->addFixup(Fixup);
295+
addFixup(MCE, FK_SecRel_4);
302296
// Emit 4 bytes (zeros) to the object file.
303-
DF->appendContents(4, 0);
297+
appendContents(4, 0);
304298
}
305299

306300
void MCWinCOFFStreamer::emitCOFFImgRel32(const MCSymbol *Symbol,
307301
int64_t Offset) {
308302
visitUsedSymbol(*Symbol);
309-
MCFragment *DF = getCurrentFragment();
310303
// Create Symbol A for the relocation relative reference.
311304
const MCExpr *MCE = MCSymbolRefExpr::create(
312305
Symbol, MCSymbolRefExpr::VK_COFF_IMGREL32, getContext());
313306
// Add the constant offset, if given.
314307
if (Offset)
315308
MCE = MCBinaryExpr::createAdd(
316309
MCE, MCConstantExpr::create(Offset, getContext()), getContext());
317-
// Build the imgrel relocation.
318-
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
319-
// Record the relocation.
320-
DF->addFixup(Fixup);
310+
addFixup(MCE, FK_Data_4);
321311
// Emit 4 bytes (zeros) to the object file.
322-
DF->appendContents(4, 0);
312+
appendContents(4, 0);
323313
}
324314

325315
void MCWinCOFFStreamer::emitCOFFSecNumber(MCSymbol const *Symbol) {
326316
visitUsedSymbol(*Symbol);
327-
MCFragment *DF = getCurrentFragment();
328317
// Create Symbol for section number.
329318
const MCExpr *MCE = MCCOFFSectionNumberTargetExpr::create(
330319
*Symbol, this->getWriter(), getContext());
331-
// Build the relocation.
332-
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
333-
// Record the relocation.
334-
DF->addFixup(Fixup);
320+
addFixup(MCE, FK_Data_4);
335321
// Emit 4 bytes (zeros) to the object file.
336-
DF->appendContents(4, 0);
322+
appendContents(4, 0);
337323
}
338324

339325
void MCWinCOFFStreamer::emitCOFFSecOffset(MCSymbol const *Symbol) {
340326
visitUsedSymbol(*Symbol);
341-
MCFragment *DF = getCurrentFragment();
342327
// Create Symbol for section offset.
343328
const MCExpr *MCE =
344329
MCCOFFSectionOffsetTargetExpr::create(*Symbol, getContext());
345-
// Build the relocation.
346-
MCFixup Fixup = MCFixup::create(DF->getContents().size(), MCE, FK_Data_4);
347-
// Record the relocation.
348-
DF->addFixup(Fixup);
330+
addFixup(MCE, FK_Data_4);
349331
// Emit 4 bytes (zeros) to the object file.
350-
DF->appendContents(4, 0);
332+
appendContents(4, 0);
351333
}
352334

353335
void MCWinCOFFStreamer::emitCommonSymbol(MCSymbol *S, uint64_t Size,

llvm/lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,45 +1033,40 @@ MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
10331033
}
10341034

10351035
void MipsTargetELFStreamer::emitGPRel32Value(const MCExpr *Value) {
1036-
MCFragment *DF = getStreamer().getCurrentFragment();
1037-
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1038-
Mips::fixup_Mips_GPREL32));
1039-
DF->appendContents(4, 0);
1036+
auto &S = getStreamer();
1037+
S.addFixup(Value, Mips::fixup_Mips_GPREL32);
1038+
S.appendContents(4, 0);
10401039
}
10411040

10421041
void MipsTargetELFStreamer::emitGPRel64Value(const MCExpr *Value) {
1043-
MCFragment *DF = getStreamer().getCurrentFragment();
1044-
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1045-
Mips::fixup_Mips_GPREL32));
1046-
DF->appendContents(8, 0);
1042+
auto &S = getStreamer();
1043+
// fixup_Mips_GPREL32 desginates R_MIPS_GPREL32+R_MIPS_64 on MIPS64.
1044+
S.addFixup(Value, Mips::fixup_Mips_GPREL32);
1045+
S.appendContents(8, 0);
10471046
}
10481047

10491048
void MipsTargetELFStreamer::emitDTPRel32Value(const MCExpr *Value) {
1050-
MCFragment *DF = getStreamer().getCurrentFragment();
1051-
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1052-
Mips::fixup_Mips_DTPREL32));
1053-
DF->appendContents(4, 0);
1049+
auto &S = getStreamer();
1050+
S.addFixup(Value, Mips::fixup_Mips_DTPREL32);
1051+
S.appendContents(4, 0);
10541052
}
10551053

10561054
void MipsTargetELFStreamer::emitDTPRel64Value(const MCExpr *Value) {
1057-
MCFragment *DF = getStreamer().getCurrentFragment();
1058-
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1059-
Mips::fixup_Mips_DTPREL64));
1060-
DF->appendContents(8, 0);
1055+
auto &S = getStreamer();
1056+
S.addFixup(Value, Mips::fixup_Mips_DTPREL64);
1057+
S.appendContents(8, 0);
10611058
}
10621059

10631060
void MipsTargetELFStreamer::emitTPRel32Value(const MCExpr *Value) {
1064-
MCFragment *DF = getStreamer().getCurrentFragment();
1065-
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1066-
Mips::fixup_Mips_TPREL32));
1067-
DF->appendContents(4, 0);
1061+
auto &S = getStreamer();
1062+
S.addFixup(Value, Mips::fixup_Mips_TPREL32);
1063+
S.appendContents(4, 0);
10681064
}
10691065

10701066
void MipsTargetELFStreamer::emitTPRel64Value(const MCExpr *Value) {
1071-
MCFragment *DF = getStreamer().getCurrentFragment();
1072-
DF->addFixup(MCFixup::create(DF->getContents().size(), Value,
1073-
Mips::fixup_Mips_TPREL64));
1074-
DF->appendContents(8, 0);
1067+
auto &S = getStreamer();
1068+
S.addFixup(Value, Mips::fixup_Mips_TPREL64);
1069+
S.appendContents(8, 0);
10751070
}
10761071

10771072
void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {

0 commit comments

Comments
 (0)