mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Propagate types from symbol to aliases.
This is similar, but not identical to what gas does. The logic in MC is to just compute the symbol table after parsing the entire file. GAS is mixed, given .type b, @object a = b b: .type b, @function It will propagate the change and make 'a' a function. Given .type b, @object b: a = b .type b, @function the type of 'a' is still object. Since we do the computation in the end, we produce a function in both cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204555 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -575,6 +575,22 @@ static uint8_t mergeTypeForSet(uint8_t origType, uint8_t newType) {
|
||||
return Type;
|
||||
}
|
||||
|
||||
static const MCSymbol *getBaseSymbol(const MCAsmLayout &Layout,
|
||||
const MCSymbol &Symbol) {
|
||||
if (!Symbol.isVariable())
|
||||
return &Symbol;
|
||||
|
||||
const MCExpr *Expr = Symbol.getVariableValue();
|
||||
MCValue Value;
|
||||
if (!Expr->EvaluateAsRelocatable(Value, &Layout))
|
||||
llvm_unreachable("Invalid Expression");
|
||||
assert(!Value.getSymB());
|
||||
const MCSymbolRefExpr *A = Value.getSymA();
|
||||
if (!A)
|
||||
return nullptr;
|
||||
return getBaseSymbol(Layout, A->getSymbol());
|
||||
}
|
||||
|
||||
void ELFObjectWriter::WriteSymbol(MCDataFragment *SymtabF,
|
||||
MCDataFragment *ShndxF,
|
||||
ELFSymbolData &MSD,
|
||||
@@ -588,7 +604,12 @@ void ELFObjectWriter::WriteSymbol(MCDataFragment *SymtabF,
|
||||
|
||||
// Binding and Type share the same byte as upper and lower nibbles
|
||||
uint8_t Binding = MCELF::GetBinding(OrigData);
|
||||
uint8_t Type = mergeTypeForSet(MCELF::GetType(OrigData), MCELF::GetType(Data));
|
||||
uint8_t Type = MCELF::GetType(OrigData);
|
||||
const MCSymbol *Base = getBaseSymbol(Layout, OrigData.getSymbol());
|
||||
if (Base) {
|
||||
MCSymbolData BaseSD = Layout.getAssembler().getSymbolData(*Base);
|
||||
Type = mergeTypeForSet(Type, MCELF::GetType(BaseSD));
|
||||
}
|
||||
if (OrigData.getFlags() & ELF_Other_ThumbFunc)
|
||||
Type = ELF::STT_FUNC;
|
||||
uint8_t Info = (Binding << ELF_STB_Shift) | (Type << ELF_STT_Shift);
|
||||
|
Reference in New Issue
Block a user