Skip to content

Commit 2fde3e1

Browse files
Revert changes made in rdar://133264719 and rdar://133001453
A significant amount of changes were made upstream to MCAssembler and MachObjectWriter that broke MCCAS. To fix them, we moved a bunch of code from MachObjectWriter to MCObjectWriter as a band-aid fix, but those are full of layering violations, this patch reverts those changes in favor of a correct fix in the next commit which involves rewriting MachOCASWriter to be a derived class if MachObjectWriter. (cherry picked from commit 91e9561)
1 parent bb8b8f0 commit 2fde3e1

File tree

9 files changed

+68
-153
lines changed

9 files changed

+68
-153
lines changed

clang/test/CAS/path-independent-cas-outputs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444

4545
// Baseline to check we got expected outputs.
4646
// RUN: %clang -target x86_64-apple-macos11 -c %s -o %t/t.o -MMD -MT dependencies -MF %t/t.d --serialize-diagnostics %t/t.dia
47-
// RUN: env LLVM_CACHE_CAS_PATH=%t/a/cas %clang-cache \
47+
// RUN: env LLVM_CACHE_CAS_PATH=%t/a/cas CLANG_CACHE_DISABLE_MCCAS=1 %clang-cache \
4848
// RUN: %clang -target x86_64-apple-macos11 -c %s -o %t/a/t1.o -MMD -MT dependencies -MF %t/a/t1.d --serialize-diagnostics %t/a/t1.dia
49-
// RUN: env LLVM_CACHE_CAS_PATH=%t/b/cas %clang-cache \
49+
// RUN: env LLVM_CACHE_CAS_PATH=%t/b/cas CLANG_CACHE_DISABLE_MCCAS=1 %clang-cache \
5050
// RUN: %clang -target x86_64-apple-macos11 -c %s -o %t/b/t2.o -MMD -MT dependencies -MF %t/b/t2.d --serialize-diagnostics %t/b/t2.dia
5151

5252
// RUN: diff %t/a/t1.o %t/b/t2.o

llvm/include/llvm/MC/MCMachOCASWriter.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -91,43 +91,6 @@ 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-
13194
void writeSymbolTable(MCAssembler &Asm) { MOW.writeSymbolTable(Asm); }
13295

13396
uint64_t writeObject(MCAssembler &Asm) override;

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ class MCMachObjectTargetWriter : public MCObjectTargetWriter {
8686

8787
class MachObjectWriter : public MCObjectWriter {
8888
public:
89+
struct DataRegionData {
90+
MachO::DataRegionType Kind;
91+
MCSymbol *Start;
92+
MCSymbol *End;
93+
};
94+
8995
// A Major version of 0 indicates that no version information was supplied
9096
// and so the corresponding load command should not be emitted.
9197
using VersionInfoType = struct {
@@ -112,6 +118,11 @@ class MachObjectWriter : public MCObjectWriter {
112118
bool operator<(const MachSymbolData &RHS) const;
113119
};
114120

121+
struct IndirectSymbolData {
122+
MCSymbol *Symbol;
123+
MCSection *Section;
124+
};
125+
115126
/// The target specific Mach-O writer instance.
116127
std::unique_ptr<MCMachObjectTargetWriter> TargetObjectWriter;
117128

@@ -132,8 +143,11 @@ class MachObjectWriter : public MCObjectWriter {
132143

133144
private:
134145
DenseMap<const MCSection *, std::vector<RelAndSymbol>> Relocations;
146+
std::vector<IndirectSymbolData> IndirectSymbols;
135147
DenseMap<const MCSection *, unsigned> IndirectSymBase;
136148

149+
std::vector<DataRegionData> DataRegions;
150+
137151
SectionAddrMap SectionAddress;
138152

139153
// List of sections in layout order. Virtual sections are after non-virtual
@@ -151,12 +165,18 @@ class MachObjectWriter : public MCObjectWriter {
151165

152166
/// @}
153167

168+
// Used to communicate Linker Optimization Hint information.
169+
MCLOHContainer LOHContainer;
170+
154171
VersionInfoType VersionInfo{};
155172
VersionInfoType TargetVariantVersionInfo{};
156173

157174
std::optional<unsigned> PtrAuthABIVersion;
158175
bool PtrAuthKernelABIVersion;
159176

177+
// The list of linker options for LC_LINKER_OPTION.
178+
std::vector<std::vector<std::string>> LinkerOptions;
179+
160180
MachSymbolData *findSymbolData(const MCSymbol &Sym);
161181

162182
void writeWithPadding(StringRef Str, uint64_t Size);
@@ -194,10 +214,15 @@ class MachObjectWriter : public MCObjectWriter {
194214

195215
bool isFixupKindPCRel(const MCAssembler &Asm, unsigned Kind);
196216

217+
std::vector<IndirectSymbolData> &getIndirectSymbols() {
218+
return IndirectSymbols;
219+
}
220+
std::vector<DataRegionData> &getDataRegions() { return DataRegions; }
197221
const llvm::SmallVectorImpl<MCSection *> &getSectionOrder() const {
198222
return SectionOrder;
199223
}
200224
SectionAddrMap &getSectionAddressMap() { return SectionAddress; }
225+
MCLOHContainer &getLOHContainer() { return LOHContainer; }
201226

202227
uint64_t getSectionAddress(const MCSection *Sec) const {
203228
return SectionAddress.lookup(Sec);
@@ -216,45 +241,43 @@ class MachObjectWriter : public MCObjectWriter {
216241
/// Mach-O deployment target version information.
217242
void setVersionMin(MCVersionMinType Type, unsigned Major, unsigned Minor,
218243
unsigned Update,
219-
VersionTuple SDKVersion = VersionTuple()) override {
244+
VersionTuple SDKVersion = VersionTuple()) {
220245
VersionInfo.EmitBuildVersion = false;
221246
VersionInfo.TypeOrPlatform.Type = Type;
222247
VersionInfo.Major = Major;
223248
VersionInfo.Minor = Minor;
224249
VersionInfo.Update = Update;
225250
VersionInfo.SDKVersion = SDKVersion;
226251
}
227-
void setBuildVersion(unsigned Platform, unsigned Major, unsigned Minor,
228-
unsigned Update,
229-
VersionTuple SDKVersion = VersionTuple()) override {
252+
void setBuildVersion(MachO::PlatformType Platform, unsigned Major,
253+
unsigned Minor, unsigned Update,
254+
VersionTuple SDKVersion = VersionTuple()) {
230255
VersionInfo.EmitBuildVersion = true;
231-
VersionInfo.TypeOrPlatform.Platform = (MachO::PlatformType)Platform;
256+
VersionInfo.TypeOrPlatform.Platform = Platform;
232257
VersionInfo.Major = Major;
233258
VersionInfo.Minor = Minor;
234259
VersionInfo.Update = Update;
235260
VersionInfo.SDKVersion = SDKVersion;
236261
}
237-
void setTargetVariantBuildVersion(unsigned Platform, unsigned Major,
238-
unsigned Minor, unsigned Update,
239-
VersionTuple SDKVersion) override {
262+
void setTargetVariantBuildVersion(MachO::PlatformType Platform,
263+
unsigned Major, unsigned Minor,
264+
unsigned Update, VersionTuple SDKVersion) {
240265
TargetVariantVersionInfo.EmitBuildVersion = true;
241-
TargetVariantVersionInfo.TypeOrPlatform.Platform =
242-
(MachO::PlatformType)Platform;
266+
TargetVariantVersionInfo.TypeOrPlatform.Platform = Platform;
243267
TargetVariantVersionInfo.Major = Major;
244268
TargetVariantVersionInfo.Minor = Minor;
245269
TargetVariantVersionInfo.Update = Update;
246270
TargetVariantVersionInfo.SDKVersion = SDKVersion;
247271
}
248272

249-
std::optional<unsigned> getPtrAuthABIVersion() const override {
273+
std::optional<unsigned> getPtrAuthABIVersion() const {
250274
return PtrAuthABIVersion;
251275
}
252-
void setPtrAuthABIVersion(unsigned V) override { PtrAuthABIVersion = V; }
253-
bool getPtrAuthKernelABIVersion() const override {
254-
return PtrAuthKernelABIVersion;
255-
}
256-
void setPtrAuthKernelABIVersion(bool V) override {
257-
PtrAuthKernelABIVersion = V;
276+
void setPtrAuthABIVersion(unsigned V) { PtrAuthABIVersion = V; }
277+
bool getPtrAuthKernelABIVersion() const { return PtrAuthKernelABIVersion; }
278+
void setPtrAuthKernelABIVersion(bool V) { PtrAuthKernelABIVersion = V; }
279+
std::vector<std::vector<std::string>> &getLinkerOptions() {
280+
return LinkerOptions;
258281
}
259282

260283
/// @}

llvm/include/llvm/MC/MCObjectWriter.h

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

12-
#include "llvm/MC/MCDirectives.h"
13-
#include "llvm/MC/MCLinkerOptimizationHint.h"
1412
#include "llvm/MC/MCSymbol.h"
1513
#include "llvm/TargetParser/Triple.h"
1614
#include <cstdint>
@@ -33,29 +31,7 @@ class MCValue;
3331
/// MCAssembler instance, which contains all the symbol and section data which
3432
/// should be emitted as part of writeObject().
3533
class MCObjectWriter {
36-
public:
37-
struct DataRegionData {
38-
unsigned Kind;
39-
MCSymbol *Start;
40-
MCSymbol *End;
41-
};
42-
4334
protected:
44-
struct IndirectSymbolData {
45-
MCSymbol *Symbol;
46-
MCSection *Section;
47-
};
48-
49-
std::vector<IndirectSymbolData> IndirectSymbols;
50-
51-
std::vector<DataRegionData> DataRegions;
52-
53-
// The list of linker options for LC_LINKER_OPTION.
54-
std::vector<std::vector<std::string>> LinkerOptions;
55-
56-
// Used to communicate Linker Optimization Hint information.
57-
MCLOHContainer LOHContainer;
58-
5935
/// List of declared file names
6036
SmallVector<std::pair<std::string, size_t>, 0> FileNames;
6137
// XCOFF specific: Optional compiler version.
@@ -84,18 +60,6 @@ class MCObjectWriter {
8460
/// \name High-Level API
8561
/// @{
8662

87-
std::vector<std::vector<std::string>> &getLinkerOptions() {
88-
return LinkerOptions;
89-
}
90-
91-
std::vector<IndirectSymbolData> &getIndirectSymbols() {
92-
return IndirectSymbols;
93-
}
94-
95-
MCLOHContainer &getLOHContainer() { return LOHContainer; }
96-
97-
std::vector<DataRegionData> &getDataRegions() { return DataRegions; }
98-
9963
/// Perform any late binding of symbols (for example, to assign symbol
10064
/// indices for use when generating relocations).
10165
///
@@ -152,12 +116,8 @@ class MCObjectWriter {
152116
SmallVector<CGProfileEntry, 0> &getCGProfile() { return CGProfile; }
153117

154118
// Mach-O specific: Whether .subsections_via_symbols is enabled.
155-
virtual bool getSubsectionsViaSymbols() const {
156-
return SubsectionsViaSymbols;
157-
}
158-
virtual void setSubsectionsViaSymbols(bool Value) {
159-
SubsectionsViaSymbols = Value;
160-
}
119+
bool getSubsectionsViaSymbols() const { return SubsectionsViaSymbols; }
120+
void setSubsectionsViaSymbols(bool Value) { SubsectionsViaSymbols = Value; }
161121

162122
/// Write the object file and returns the number of bytes written.
163123
///
@@ -166,22 +126,6 @@ class MCObjectWriter {
166126
/// generated.
167127
virtual uint64_t writeObject(MCAssembler &Asm) = 0;
168128

169-
virtual void setVersionMin(MCVersionMinType Type, unsigned Major,
170-
unsigned Minor, unsigned Update,
171-
VersionTuple SDKVersion = VersionTuple()) {}
172-
virtual void setBuildVersion(unsigned Platform, unsigned Major,
173-
unsigned Minor, unsigned Update,
174-
VersionTuple SDKVersion = VersionTuple()) {}
175-
176-
virtual void setTargetVariantBuildVersion(unsigned Platform, unsigned Major,
177-
unsigned Minor, unsigned Update,
178-
VersionTuple SDKVersion) {}
179-
virtual std::optional<unsigned> getPtrAuthABIVersion() const {
180-
return std::nullopt;
181-
}
182-
virtual void setPtrAuthABIVersion(unsigned V) {}
183-
virtual bool getPtrAuthKernelABIVersion() const { return false; }
184-
virtual void setPtrAuthKernelABIVersion(bool V) {}
185129
/// @}
186130
};
187131

llvm/include/llvm/MC/MCSPIRVObjectWriter.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ 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-
5248
private:
5349
void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
5450
const MCFixup &Fixup, MCValue Target,

0 commit comments

Comments
 (0)