[LLVMdev] RFC: Supporting ELF symbol aliases via GlobalAlias GEPs
Dan Gohman
gohman at apple.com
Tue Aug 25 10:11:16 PDT 2009
Hello David,
This feature sounds reasonable to me. Please update the patch to
include a feature test, and LangRef.html changes as necessary,
including a mention that the feature depends on the target.
Here are a few misc. comments on the patch itself:
+ /// isTargetElf - returns true if the target is ELF.
+ virtual bool isTargetElf() const { return true; }
This does not belong in TargetMachine.h.
+ if ((GEP = dyn_cast<ConstantExpr>(I->getAliasee()))
+ && (GEP->getOpcode() == Instruction::GetElementPtr)) {
Please follow LLVM style.
+ assert(PrintGlobalOffsetAlias(cast<GlobalAlias>(I)) &&
+ "Target doesn't support offset aliases.");
This won't call PrintGlobalOffsetAlias when asserts are disabled.
Thanks,
Dan
On Aug 25, 2009, at 9:07 AM, David Chisnall wrote:
> I've attached a less-hackish implementation of this. This includes
> the following modifications:
>
> - getSupportsOverlappingAliases() method on TargetMachine which
> returns whether the target supports multiple symbols to the same
> object. This returns false in the superclass and needs to be
> explicitly overridden for each target to enable it.
>
> - An implementation of this method in X86TargetMachine which returns
> true for ELF targets.
>
> - printObjectType() in AsmPrinter. Currently all of the subclasses
> hard-code this (e.g. ".type " + name + ", @object") when emitting
> global variables. I've implemented this for X86ATTAsmWPrinter, and
> will add the same for other classes as required.
>
> - PrintGlobalOffsetAlias(), also in AsmPrinter. This outputs a
> GlobalAlias which is a GEP to a GlobalVariable, if the target
> supports it.
>
> This is a proof-of-concept implementation which, pending review, I'd
> like to commit as a work-in-progress and then work on adding support
> for more targets. It should be relatively trivial to add this for
> other ELF targets; just override getSupportsOverlappingAliases() in
> the relevant TargetMachine subclass to return true and copy the code
> out of the PrintGlobalVariable() method in the AsmPrinter subclass
> to implement printObjectType().
>
> David
>
> On 23 Aug 2009, at 23:41, David Chisnall wrote:
>
>> Hi Everyone,
>>
>> Chris suggested[1] I should ask for feedback as to whether this is
>> a desired feature before I put too much effort into it, so here goes:
>>
>> I would like to be able to export a symbol that is inside an LLVM
>> structure. This is possible on ELF targets[2], and the attached
>> proof-of-concept patch to AsmWriter makes it work (although in a
>> hackish way that I am NOT suggesting be committed as-is).
>>
>> With this patch, the you can compile this:
>>
>> %0 = type { i32, i32 }
>> @structure = global %0 { i32 0, i32 1 }
>> @element1 = alias getelementptr( %0* @structure, i32 0, i32 1)
>>
>> To this:
>>
>> .subsections_via_symbols
>> .section __DATA,__data
>> .align 3
>> _structure: ##
>> @structure
>> .space 4
>> .long 1 ## 0x1
>>
>> .globl _element1
>> .set _element1, _structure+4
>> .size _element1, 4
>> .type _element1, at object
>>
>> The element1 symbol is an i32* pointing to element 1 in the
>> structure (the one emitted by .long 1).
>>
>> There are really two questions here:
>>
>> 1) Do we want to be able to generate this kind of output at all (I
>> do!)
>> 2) If we do, do we want to use the global alias initialised with a
>> constant GEP to do it, or provide some other mechanism?
>>
>> David
>>
>> [1] http://llvm.org/bugs/show_bug.cgi?id=4739#c24
>> [2] I know it's not possible on Mach-O (well, it is for internal
>> symbols, just not for ones exported via the symbol table) - does
>> anyone know if PE allows it?
>> <llvm.diff>
>
> <llvm.diff>_______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list