[LLVMdev] RFC: Supporting ELF symbol aliases via GlobalAlias GEPs

David Chisnall csdavec at swansea.ac.uk
Tue Aug 25 09:07:12 PDT 2009


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>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm.diff
Type: application/octet-stream
Size: 7030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090825/14730f86/attachment.obj>


More information about the llvm-dev mailing list