[clang] [llvm] [MC] Remove Darwin SDK/Version from ObjFileInfo (PR #103025)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 13 02:10:51 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-llvm-binary-utilities
Author: Alexis Engelke (aengelke)
<details>
<summary>Changes</summary>
There's only a single user (MCMachOStreamer), so it makes more sense to move the version emission to the source of the data.
(Not sure whether we want this, but I don't see benefits in storing this information in the MCObjectFileInfo.)
---
Full diff: https://github.com/llvm/llvm-project/pull/103025.diff
5 Files Affected:
- (modified) clang/tools/driver/cc1as_main.cpp (+7-4)
- (modified) llvm/include/llvm/MC/MCObjectFileInfo.h (-26)
- (modified) llvm/lib/MC/MCMachOStreamer.cpp (+2-8)
- (modified) llvm/lib/Object/ModuleSymbolTable.cpp (-1)
- (modified) llvm/tools/llvm-mc/llvm-mc.cpp (+3)
``````````diff
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index b661a43c88b08d..78019d39742e64 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -489,10 +489,6 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
std::unique_ptr<MCObjectFileInfo> MOFI(
TheTarget->createMCObjectFileInfo(Ctx, PIC));
- if (Opts.DarwinTargetVariantTriple)
- MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
- if (!Opts.DarwinTargetVariantSDKVersion.empty())
- MOFI->setDarwinTargetVariantSDKVersion(Opts.DarwinTargetVariantSDKVersion);
Ctx.setObjectFileInfo(MOFI.get());
if (Opts.GenDwarfForAssembly)
@@ -574,6 +570,13 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
Str.reset(TheTarget->createMCObjectStreamer(
T, Ctx, std::move(MAB), std::move(OW), std::move(CE), *STI));
Str.get()->initSections(Opts.NoExecStack, *STI);
+ if (T.isOSBinFormatMachO() && T.isOSDarwin()) {
+ Triple *TVT = Opts.DarwinTargetVariantTriple
+ ? &*Opts.DarwinTargetVariantTriple
+ : nullptr;
+ Str->emitVersionForTarget(T, VersionTuple(), TVT,
+ Opts.DarwinTargetVariantSDKVersion);
+ }
}
// When -fembed-bitcode is passed to clang_as, a 1-byte marker
diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h
index dda3e8a020f3ae..e2a2c84e47910b 100644
--- a/llvm/include/llvm/MC/MCObjectFileInfo.h
+++ b/llvm/include/llvm/MC/MCObjectFileInfo.h
@@ -458,9 +458,6 @@ class MCObjectFileInfo {
private:
bool PositionIndependent = false;
MCContext *Ctx = nullptr;
- VersionTuple SDKVersion;
- std::optional<Triple> DarwinTargetVariantTriple;
- VersionTuple DarwinTargetVariantSDKVersion;
void initMachOMCObjectFileInfo(const Triple &T);
void initELFMCObjectFileInfo(const Triple &T, bool Large);
@@ -471,29 +468,6 @@ class MCObjectFileInfo {
void initXCOFFMCObjectFileInfo(const Triple &T);
void initDXContainerObjectFileInfo(const Triple &T);
MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const;
-
-public:
- void setSDKVersion(const VersionTuple &TheSDKVersion) {
- SDKVersion = TheSDKVersion;
- }
-
- const VersionTuple &getSDKVersion() const { return SDKVersion; }
-
- void setDarwinTargetVariantTriple(const Triple &T) {
- DarwinTargetVariantTriple = T;
- }
-
- const Triple *getDarwinTargetVariantTriple() const {
- return DarwinTargetVariantTriple ? &*DarwinTargetVariantTriple : nullptr;
- }
-
- void setDarwinTargetVariantSDKVersion(const VersionTuple &TheSDKVersion) {
- DarwinTargetVariantSDKVersion = TheSDKVersion;
- }
-
- const VersionTuple &getDarwinTargetVariantSDKVersion() const {
- return DarwinTargetVariantSDKVersion;
- }
};
} // end namespace llvm
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index 528caa12ec2126..2e3b67eca08c1d 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -533,14 +533,8 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context,
std::unique_ptr<MCCodeEmitter> &&CE,
bool DWARFMustBeAtTheEnd,
bool LabelSections) {
- MCMachOStreamer *S = new MCMachOStreamer(
- Context, std::move(MAB), std::move(OW), std::move(CE), LabelSections);
- const Triple &Target = Context.getTargetTriple();
- S->emitVersionForTarget(
- Target, Context.getObjectFileInfo()->getSDKVersion(),
- Context.getObjectFileInfo()->getDarwinTargetVariantTriple(),
- Context.getObjectFileInfo()->getDarwinTargetVariantSDKVersion());
- return S;
+ return new MCMachOStreamer(Context, std::move(MAB), std::move(OW),
+ std::move(CE), LabelSections);
}
// The AddrSig section uses a series of relocations to refer to the symbols that
diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp
index d8f520ad02c2f2..fb36a88b9c7149 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -109,7 +109,6 @@ initializeRecordStreamer(const Module &M,
MCContext MCCtx(TT, MAI.get(), MRI.get(), STI.get(), &SrcMgr);
std::unique_ptr<MCObjectFileInfo> MOFI(
T->createMCObjectFileInfo(MCCtx, /*PIC=*/false));
- MOFI->setSDKVersion(M.getSDKVersion());
MCCtx.setObjectFileInfo(MOFI.get());
RecordStreamer Streamer(MCCtx, M);
T->createNullTargetStreamer(Streamer);
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index 3a44ddf17974a4..e65b8f62369520 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -559,6 +559,9 @@ int main(int argc, char **argv) {
std::unique_ptr<MCCodeEmitter>(CE), *STI));
if (NoExecStack)
Str->initSections(true, *STI);
+ if (TheTriple.isOSBinFormatMachO() && TheTriple.isOSDarwin())
+ Str->emitVersionForTarget(TheTriple, VersionTuple(), nullptr,
+ VersionTuple());
}
int Res = 1;
``````````
</details>
https://github.com/llvm/llvm-project/pull/103025
More information about the llvm-commits
mailing list