mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-23 00:20:25 +00:00
Fix PR18743.
The IR @foo = private constant i32 42 is valid, but before this patch we would produce an invalid MachO from it. It was invalid because it would use an L label in a section where the liker needs the labels in order to atomize it. One way of fixing it would be to just reject this IR in the backend, but that would not be very front end friendly. What this patch does is use an 'l' prefix in sections that we know the linker requires symbols for atomizing them. This allows frontends to just use private and not worry about which sections they go to or how the linker handles them. One small issue with this strategy is that now a symbol name depends on the section, which is not available before codegen. This is not a problem in practice. The reason is that it only happens with private linkage, which will be ignored by the non codegen users (llvm-nm and llvm-ar). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201608 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetLowering.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
using namespace llvm;
|
||||
|
||||
@@ -99,30 +100,22 @@ static bool IsNullTerminatedString(const Constant *C) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Return the MCSymbol for the specified global value. This
|
||||
/// symbol is the main label that is the address of the global.
|
||||
MCSymbol *TargetLoweringObjectFile::getSymbol(const GlobalValue *GV,
|
||||
Mangler &M) const {
|
||||
SmallString<60> NameStr;
|
||||
M.getNameWithPrefix(NameStr, GV);
|
||||
return Ctx->GetOrCreateSymbol(NameStr.str());
|
||||
}
|
||||
|
||||
MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
|
||||
const GlobalValue *GV, StringRef Suffix, Mangler &M) const {
|
||||
const GlobalValue *GV, StringRef Suffix, Mangler &Mang,
|
||||
const TargetMachine &TM) const {
|
||||
assert(!Suffix.empty());
|
||||
|
||||
SmallString<60> NameStr;
|
||||
NameStr += DL->getPrivateGlobalPrefix();
|
||||
M.getNameWithPrefix(NameStr, GV);
|
||||
TM.getTargetLowering()->getNameWithPrefix(NameStr, GV, Mang);
|
||||
NameStr.append(Suffix.begin(), Suffix.end());
|
||||
return Ctx->GetOrCreateSymbol(NameStr.str());
|
||||
}
|
||||
|
||||
MCSymbol *TargetLoweringObjectFile::
|
||||
getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
||||
MachineModuleInfo *MMI) const {
|
||||
return getSymbol(GV, Mang);
|
||||
MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
|
||||
const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
|
||||
MachineModuleInfo *MMI) const {
|
||||
return TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||
}
|
||||
|
||||
void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
|
||||
@@ -275,6 +268,10 @@ SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
|
||||
return SelectSectionForGlobal(GV, Kind, Mang, TM);
|
||||
}
|
||||
|
||||
bool TargetLoweringObjectFile::isSectionAtomizableBySymbols(
|
||||
const MCSection &Section) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Lame default implementation. Calculate the section name for global.
|
||||
const MCSection *
|
||||
@@ -312,9 +309,11 @@ TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const {
|
||||
/// handling information.
|
||||
const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
|
||||
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
||||
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
||||
const TargetMachine &TM, MachineModuleInfo *MMI,
|
||||
MCStreamer &Streamer) const {
|
||||
const MCSymbolRefExpr *Ref =
|
||||
MCSymbolRefExpr::Create(getSymbol(GV, Mang), getContext());
|
||||
MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GV, Mang),
|
||||
getContext());
|
||||
|
||||
return getTTypeReference(Ref, Encoding, Streamer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user