Skip to content

Commit 04ceff2

Browse files
Merge pull request swiftlang#9046 from rastogishubham/FixLCStable
Fix MCCAS dropping LC_BUILD_VERSION
2 parents 4ffdc61 + 059f31a commit 04ceff2

File tree

5 files changed

+92
-21
lines changed

5 files changed

+92
-21
lines changed

llvm/include/llvm/MC/MCMachOCASWriter.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,43 @@ class MachOCASWriter : public MCObjectWriter {
9191
MOW.writeDataInCodeRegion(Asm);
9292
}
9393

94+
void setVersionMin(MCVersionMinType Type, unsigned Major, unsigned Minor,
95+
unsigned Update,
96+
VersionTuple SDKVersion = VersionTuple()) override {
97+
MOW.setVersionMin(Type, Major, Minor, Update, SDKVersion);
98+
}
99+
void setBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
100+
unsigned Update,
101+
VersionTuple SDKVersion = VersionTuple()) override {
102+
MOW.setBuildVersion(Platform, Major, Minor, Update, SDKVersion);
103+
}
104+
void setTargetVariantBuildVersion(unsigned Platform, unsigned Major,
105+
unsigned Minor, unsigned Update,
106+
VersionTuple SDKVersion) override {
107+
MOW.setTargetVariantBuildVersion(Platform, Major, Minor, Update,
108+
SDKVersion);
109+
}
110+
111+
std::optional<unsigned> getPtrAuthABIVersion() const override {
112+
return MOW.getPtrAuthABIVersion();
113+
}
114+
void setPtrAuthABIVersion(unsigned V) override {
115+
MOW.setPtrAuthABIVersion(V);
116+
}
117+
bool getPtrAuthKernelABIVersion() const override {
118+
return MOW.getPtrAuthKernelABIVersion();
119+
}
120+
void setPtrAuthKernelABIVersion(bool V) override {
121+
MOW.setPtrAuthKernelABIVersion(V);
122+
}
123+
124+
bool getSubsectionsViaSymbols() const override {
125+
return MOW.getSubsectionsViaSymbols();
126+
}
127+
void setSubsectionsViaSymbols(bool Value) override {
128+
MOW.setSubsectionsViaSymbols(Value);
129+
}
130+
94131
void writeSymbolTable(MCAssembler &Asm) { MOW.writeSymbolTable(Asm); }
95132

96133
uint64_t writeObject(MCAssembler &Asm) override;

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,41 +241,46 @@ class MachObjectWriter : public MCObjectWriter {
241241
/// Mach-O deployment target version information.
242242
void setVersionMin(MCVersionMinType Type, unsigned Major, unsigned Minor,
243243
unsigned Update,
244-
VersionTuple SDKVersion = VersionTuple()) {
244+
VersionTuple SDKVersion = VersionTuple()) override {
245245
VersionInfo.EmitBuildVersion = false;
246246
VersionInfo.TypeOrPlatform.Type = Type;
247247
VersionInfo.Major = Major;
248248
VersionInfo.Minor = Minor;
249249
VersionInfo.Update = Update;
250250
VersionInfo.SDKVersion = SDKVersion;
251251
}
252-
void setBuildVersion(MachO::PlatformType Platform, unsigned Major,
253-
unsigned Minor, unsigned Update,
254-
VersionTuple SDKVersion = VersionTuple()) {
252+
void setBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
253+
unsigned Update,
254+
VersionTuple SDKVersion = VersionTuple()) override {
255255
VersionInfo.EmitBuildVersion = true;
256-
VersionInfo.TypeOrPlatform.Platform = Platform;
256+
VersionInfo.TypeOrPlatform.Platform = (MachO::PlatformType)Platform;
257257
VersionInfo.Major = Major;
258258
VersionInfo.Minor = Minor;
259259
VersionInfo.Update = Update;
260260
VersionInfo.SDKVersion = SDKVersion;
261261
}
262-
void setTargetVariantBuildVersion(MachO::PlatformType Platform,
263-
unsigned Major, unsigned Minor,
264-
unsigned Update, VersionTuple SDKVersion) {
262+
void setTargetVariantBuildVersion(unsigned Platform, unsigned Major,
263+
unsigned Minor, unsigned Update,
264+
VersionTuple SDKVersion) override {
265265
TargetVariantVersionInfo.EmitBuildVersion = true;
266-
TargetVariantVersionInfo.TypeOrPlatform.Platform = Platform;
266+
TargetVariantVersionInfo.TypeOrPlatform.Platform =
267+
(MachO::PlatformType)Platform;
267268
TargetVariantVersionInfo.Major = Major;
268269
TargetVariantVersionInfo.Minor = Minor;
269270
TargetVariantVersionInfo.Update = Update;
270271
TargetVariantVersionInfo.SDKVersion = SDKVersion;
271272
}
272273

273-
std::optional<unsigned> getPtrAuthABIVersion() const {
274+
std::optional<unsigned> getPtrAuthABIVersion() const override {
274275
return PtrAuthABIVersion;
275276
}
276-
void setPtrAuthABIVersion(unsigned V) { PtrAuthABIVersion = V; }
277-
bool getPtrAuthKernelABIVersion() const { return PtrAuthKernelABIVersion; }
278-
void setPtrAuthKernelABIVersion(bool V) { PtrAuthKernelABIVersion = V; }
277+
void setPtrAuthABIVersion(unsigned V) override { PtrAuthABIVersion = V; }
278+
bool getPtrAuthKernelABIVersion() const override {
279+
return PtrAuthKernelABIVersion;
280+
}
281+
void setPtrAuthKernelABIVersion(bool V) override {
282+
PtrAuthKernelABIVersion = V;
283+
}
279284
std::vector<std::vector<std::string>> &getLinkerOptions() {
280285
return LinkerOptions;
281286
}

llvm/include/llvm/MC/MCObjectWriter.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_MC_MCOBJECTWRITER_H
1010
#define LLVM_MC_MCOBJECTWRITER_H
1111

12+
#include "llvm/MC/MCDirectives.h"
1213
#include "llvm/MC/MCSymbol.h"
1314
#include "llvm/TargetParser/Triple.h"
1415
#include <cstdint>
@@ -116,8 +117,12 @@ class MCObjectWriter {
116117
SmallVector<CGProfileEntry, 0> &getCGProfile() { return CGProfile; }
117118

118119
// Mach-O specific: Whether .subsections_via_symbols is enabled.
119-
bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; }
120-
void setSubsectionsViaSymbols(bool Value) { SubsectionsViaSymbols = Value; }
120+
virtual bool getSubsectionsViaSymbols() const {
121+
return SubsectionsViaSymbols;
122+
}
123+
virtual void setSubsectionsViaSymbols(bool Value) {
124+
SubsectionsViaSymbols = Value;
125+
}
121126

122127
/// Write the object file and returns the number of bytes written.
123128
///
@@ -126,6 +131,22 @@ class MCObjectWriter {
126131
/// generated.
127132
virtual uint64_t writeObject(MCAssembler &Asm) = 0;
128133

134+
virtual void setVersionMin(MCVersionMinType Type, unsigned Major,
135+
unsigned Minor, unsigned Update,
136+
VersionTuple SDKVersion = VersionTuple()) {}
137+
virtual void setBuildVersion(unsigned Platform, unsigned Major,
138+
unsigned Minor, unsigned Update,
139+
VersionTuple SDKVersion = VersionTuple()) {}
140+
141+
virtual void setTargetVariantBuildVersion(unsigned Platform, unsigned Major,
142+
unsigned Minor, unsigned Update,
143+
VersionTuple SDKVersion) {}
144+
virtual std::optional<unsigned> getPtrAuthABIVersion() const {
145+
return std::nullopt;
146+
}
147+
virtual void setPtrAuthABIVersion(unsigned V) {}
148+
virtual bool getPtrAuthKernelABIVersion() const { return false; }
149+
virtual void setPtrAuthKernelABIVersion(bool V) {}
129150
/// @}
130151
};
131152

llvm/include/llvm/MC/MCSPIRVObjectWriter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class SPIRVObjectWriter final : public MCObjectWriter {
4545

4646
void setBuildVersion(unsigned Major, unsigned Minor, unsigned Bound);
4747

48+
void setBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
49+
unsigned Update,
50+
VersionTuple SDKVersion = VersionTuple()) override {}
51+
4852
private:
4953
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
5054
const MCFixup &Fixup, MCValue Target,

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class MCMachOStreamer : public MCObjectStreamer {
8282
return static_cast<MachObjectWriter &>(getAssembler().getWriter());
8383
}
8484

85+
MCObjectWriter &getMCObjectWriter() {
86+
return static_cast<MCObjectWriter &>(getAssembler().getWriter());
87+
}
88+
8589
/// @name MCStreamer Interface
8690
/// @{
8791

@@ -222,7 +226,7 @@ void MCMachOStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
222226
case MCAF_Code32: return; // Change parsing mode; no-op here.
223227
case MCAF_Code64: return; // Change parsing mode; no-op here.
224228
case MCAF_SubsectionsViaSymbols:
225-
getWriter().setSubsectionsViaSymbols(true);
229+
getMCObjectWriter().setSubsectionsViaSymbols(true);
226230
return;
227231
}
228232
}
@@ -254,21 +258,21 @@ void MCMachOStreamer::emitDataRegion(MCDataRegionType Kind) {
254258
void MCMachOStreamer::emitVersionMin(MCVersionMinType Kind, unsigned Major,
255259
unsigned Minor, unsigned Update,
256260
VersionTuple SDKVersion) {
257-
getWriter().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
261+
getMCObjectWriter().setVersionMin(Kind, Major, Minor, Update, SDKVersion);
258262
}
259263

260264
void MCMachOStreamer::emitBuildVersion(unsigned Platform, unsigned Major,
261265
unsigned Minor, unsigned Update,
262266
VersionTuple SDKVersion) {
263-
getWriter().setBuildVersion((MachO::PlatformType)Platform, Major, Minor,
264-
Update, SDKVersion);
267+
getMCObjectWriter().setBuildVersion((MachO::PlatformType)Platform, Major,
268+
Minor, Update, SDKVersion);
265269
}
266270

267271
void MCMachOStreamer::emitDarwinTargetVariantBuildVersion(
268272
unsigned Platform, unsigned Major, unsigned Minor, unsigned Update,
269273
VersionTuple SDKVersion) {
270-
getWriter().setTargetVariantBuildVersion((MachO::PlatformType)Platform, Major,
271-
Minor, Update, SDKVersion);
274+
getMCObjectWriter().setTargetVariantBuildVersion(
275+
(MachO::PlatformType)Platform, Major, Minor, Update, SDKVersion);
272276
}
273277

274278
void MCMachOStreamer::EmitPtrAuthABIVersion(unsigned PtrAuthABIVersion,

0 commit comments

Comments
 (0)