Skip to content

[MC] Remove Darwin SDK/Version from ObjFileInfo #103025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions clang/tools/driver/cc1as_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions llvm/include/llvm/MC/MCObjectFileInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions llvm/lib/MC/MCMachOStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Object/ModuleSymbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular and Thin LTO use ModuleSymbolTable to record symbols in the IR file (llvm-nm a.bc). Will this cause a behavior difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so? I would expect that the information is always stored in the module -- and all call sites that create a MCObjectStreamer take the information from the module (the only reader of the MOFI fields was createMachOStreamer, but emitVersionForTarget is always (also) called from the AsmPrinter). I'm just 95% confident: tests pass + local code changes seem reasonable to me, but I certainly miss the "big picture" regarding LTO.

MCCtx.setObjectFileInfo(MOFI.get());
RecordStreamer Streamer(MCCtx, M);
T->createNullTargetStreamer(Streamer);
Expand Down
2 changes: 2 additions & 0 deletions llvm/tools/llvm-mc/llvm-mc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ int main(int argc, char **argv) {
std::unique_ptr<MCCodeEmitter>(CE), *STI));
if (NoExecStack)
Str->initSections(true, *STI);
Str->emitVersionForTarget(TheTriple, VersionTuple(), nullptr,
VersionTuple());
}

int Res = 1;
Expand Down
Loading