[LLVMdev] ARM assembler's syntax in clang

Tim Northover t.p.northover at gmail.com
Thu Mar 7 12:59:19 PST 2013

Hi Ashi,

> ld: illegal text-relocation to _data_table in table.o from foo in
> use_table.o for architecture armv7

It looks like you're using iOS. I'm not familiar with the exact
workings of that platform, but I think a similar message would occur
in ELF-land.

If iOS *is* comparable, your issue is that symbols in dynamically
loaded objects can't (usually) be referenced directly because the code
section (and any embedded litpools) need to be identical no matter
where everything is loaded in memory. This is most of the point of
.dylib files: the instructions only have to exist once in memory and
can be shared. If the bytes would be different for each user that's
not possible --  the linker spots places where that happens and gives
an error.

My advice would be to compile a .c file  (with "-S" to view the
assembly) which makes accesses like you're trying to do and copy its
code. There's no shame in it: I had a good idea of what ELF did but
still got the syntactic details wrong when I tried to write similar
code off the top of my head.

In this case, for example, I'd compile the C code (with "-fPIC" in
principle, though it seems to make no difference here. Actually, I'm
rather disturbed that you're trying to compile the C part of a .dylib
without "-fPIC". In the Linux world that's a no-no. Could be valid for
iOS, but I'd suggest you make sure if you don't know):

extern int data_table[];

int *wheres_data_table(void) {
    return &data_table[0];

(N.b. "armv7" uses a movw/movt pair which is perfectly valid. If you
want to see how to do it using litpools, you need to compile for
"armv6" which doesn't have those instructions).



More information about the llvm-dev mailing list