-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Description
| Bugzilla Link | 24486 |
| Resolution | FIXED |
| Resolved on | Oct 05, 2015 07:49 |
| Version | unspecified |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
Extended Description
Trying to resolve this https://code.google.com/p/address-sanitizer/issues/detail?id=398 issue, I found out, that clang integrated-as doesn't support local aliases to global variables (GNU assembler does). Consider the following testcase:
$ cat test.s
.data
.global foo
foo:
.long
bar = foo
.long bar
$ clang -c tmp.s && readelf -r tmp.o
Relocation section '.rela.data' at offset 0x90 contains 1 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000000000 00020000000a R_X86_64_32 0000000000000000 foo + 0
$ gcc -c tmp.s && readelf -r tmp.o
Relocation section '.rela.data' at offset 0x318 contains 1 entries:
Offset Info Type Sym. Value Sym. Name + Addend
000000000000 00020000000a R_X86_64_32 0000000000000000 .data + 0
While GNU as generates relocation for "bar", addressing local .data storage, clang integrated as addresses it to its aliasee, global variable "foo", that might be located in completely different place (e.g. when shared library and executable define the same global variable).
After some investigation, I found out, that the code responsible for Sym. Name entry in '.rela.data' section located here:
$ cat lib/MC/MCExpr.cpp
bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const MCFixup *Fixup,
const SectionAddrMap *Addrs,
bool InSet) const {
.........................
case SymbolRef: {
const MCSymbolRefExpr *SRE = cast<MCSymbolRefExpr>(this);
const MCSymbol &Sym = SRE->getSymbol();
// Evaluate recursively if this is a variable.
if (Sym.isVariable() && SRE->getKind() == MCSymbolRefExpr::VK_None &&
canExpand(Sym, Asm, InSet)) {
bool IsMachO = SRE->hasSubsectionsViaSymbols();
if (Sym.getVariableValue()->evaluateAsRelocatableImpl(
Res, Asm, Layout, Fixup, Addrs, InSet || IsMachO)) {
........................
}
Is this the right place to fix the issue? Could someone more familiar with Clang/LLVM code base help me to cook proper fix?