Skip to content

Commit 3588a8a

Browse files
Fix CAS failures on rebranch
rdar://133264719 (🌲6.0+1 CAS failures on rebranch) Because of eb22392, the LinkerOptions have been moved from MCAssembler to MachObjectWriter, but MachOCASWriter doesn't have access to those linker options, this patch fixes the bug by moving the LinkerOptions to MCObjectWriter instead.
1 parent 04f5dc0 commit 3588a8a

File tree

6 files changed

+11
-8
lines changed

6 files changed

+11
-8
lines changed

llvm/include/llvm/MC/MCMachObjectWriter.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ class MachObjectWriter : public MCObjectWriter {
174174
std::optional<unsigned> PtrAuthABIVersion;
175175
bool PtrAuthKernelABIVersion;
176176

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

182179
void writeWithPadding(StringRef Str, uint64_t Size);
@@ -281,9 +278,6 @@ class MachObjectWriter : public MCObjectWriter {
281278
void setPtrAuthKernelABIVersion(bool V) override {
282279
PtrAuthKernelABIVersion = V;
283280
}
284-
std::vector<std::vector<std::string>> &getLinkerOptions() {
285-
return LinkerOptions;
286-
}
287281

288282
/// @}
289283

llvm/include/llvm/MC/MCObjectWriter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class MCValue;
3333
/// should be emitted as part of writeObject().
3434
class MCObjectWriter {
3535
protected:
36+
// The list of linker options for LC_LINKER_OPTION.
37+
std::vector<std::vector<std::string>> LinkerOptions;
38+
3639
/// List of declared file names
3740
SmallVector<std::pair<std::string, size_t>, 0> FileNames;
3841
// XCOFF specific: Optional compiler version.
@@ -61,6 +64,10 @@ class MCObjectWriter {
6164
/// \name High-Level API
6265
/// @{
6366

67+
std::vector<std::vector<std::string>> &getLinkerOptions() {
68+
return LinkerOptions;
69+
}
70+
6471
/// Perform any late binding of symbols (for example, to assign symbol
6572
/// indices for use when generating relocations).
6673
///

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void MCMachOStreamer::emitAssemblerFlag(MCAssemblerFlag Flag) {
232232
}
233233

234234
void MCMachOStreamer::emitLinkerOptions(ArrayRef<std::string> Options) {
235-
getWriter().getLinkerOptions().push_back(Options);
235+
getMCObjectWriter().getLinkerOptions().push_back(Options);
236236
}
237237

238238
void MCMachOStreamer::emitDataRegion(MCDataRegionType Kind) {

llvm/lib/MC/MCObjectWriter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void MCObjectWriter::reset() {
2525
EmitAddrsigSection = false;
2626
SubsectionsViaSymbols = false;
2727
CGProfile.clear();
28+
LinkerOptions.clear();
2829
}
2930

3031
bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void MachObjectWriter::reset() {
6363
TargetVariantVersionInfo.SDKVersion = VersionTuple();
6464
PtrAuthABIVersion = std::nullopt;
6565
PtrAuthKernelABIVersion = false;
66-
LinkerOptions.clear();
6766
MCObjectWriter::reset();
6867
}
6968

llvm/test/MC/MachO/linker-options.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
; RUN: llc -O0 -mtriple=x86_64-apple-darwin -filetype=obj -o - %s | llvm-readobj --macho-linker-options - > %t
88
; RUN: FileCheck --check-prefix=CHECK-OBJ < %t %s
9+
; RUN: mkdir -p %t.dir/cas
10+
; RUN: llc -O0 -mtriple=x86_64-apple-darwin -filetype=obj --cas %t.dir/cas -cas-backend -o - %s | llvm-readobj --macho-linker-options - > %t
911

1012
; CHECK-OBJ: Linker Options {
1113
; CHECK-OBJ: Size: 16

0 commit comments

Comments
 (0)