[llvm-dev] How to create global symbol from record offset
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Sat Oct 31 07:14:41 PDT 2015
On 31 October 2015 at 03:19, Nat! via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> I have a problem getting this implemented, the following small test program
> invariably crashes with.
It looks like you're trying to use a GetElementPtr on a constant
struct directly. You can't do that because GEP produces a pointer and
a constant struct doesn't have any kind of address: so the first
argument to a GEP has to be a pointer of some kind.
>From your original question you probably want to make the constant
struct the initializer of some global variable and then create a GEP
based on that global instead. Also, if you haven't seen it already
take a look at http://llvm.org/docs/GetElementPtr.html. You'll
probably have to provide an extra index to the GEP.
Finally, if you already have LLVM IR that does what you want, try "llc
-march=cpp" on it. You'll get the C++ code you need to write to
produce that IR. You wouldn't usually want to copy/paste it directly
(computer-generated code!) but it can be very useful to see what it's
doing differently and where you've gone wrong.
More information about the llvm-dev