[LLVMdev] Changing the design of GlobalAliases to represent what is actually possible in object files.

Rafael Espíndola rafael.espindola at gmail.com
Fri May 23 14:37:32 PDT 2014


>> > For example, it would not be possible to define an absolute symbol to be
>> > the offset between two symbols.  In some restricted circumstances —
>> > if both symbols are global variables in the same section and defined
>> > in the same translation unit — this could be worked around.
>> >
>> > But I’ll gladly admit that I don’t have a use case in mind for that
>> > feature.
>> > Absolute symbols are useful, and storing offsets between symbols into
>> > global memory is useful, but I don’t know why you’d combine them.
>>
>> That is funny. I, on the other hand, think that this is the best
>> argument I have seen for keeping aliases pointing to ConstantExpr so
>> far.
>
>
> IMO if we want to support defining symbols at absolute addresses, we should
> add a separate construct for this.  So far everyone has gotten by with
> linker flags and scripts, though.

Well, if we support an arbitrary ConstantExtpr it is hard not to
support absolute symbols.

Attached is a work in progress on trying to see how hard it would be
to implement support for arbitrary ConstantExpr.  I is fairly
incomplete. In particular, the linker need to be updated. But it can
already codegen things like

------------------------------------------------------------------------------
@foo = global i32 42
@test1 = alias getelementptr(i32 *@foo, i32 1)

; absolute: 42
@test2 = alias inttoptr(i32 42 to i32*)

@test3 = alias inttoptr(i64 ptrtoint (i32* @foo to i64) to i32*)

; absolute: 4
@test4 = alias inttoptr(i64 sub (i64 ptrtoint (i32* @test1 to i64),
                                 i64 ptrtoint (i32* @foo to i64)) to i32*)
------------------------------------------------------------------------------------------

I have to run now, but will try to get something that I can send for
proper code review during the weekend.

Judging from what I have seen so far I would be OK with

* Supporting only symbol + offset and representing that directly.
* Supporting "any" ConstantExpr.

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: application/octet-stream
Size: 33307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140523/98dcaead/attachment.obj>


More information about the llvm-dev mailing list