aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ld/data.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-01-23 22:51:39 -0500
committerRuss Cox <rsc@golang.org>2014-01-23 22:51:39 -0500
commitb377c9c6a9b720d0897d298652bebd3887ceeb46 (patch)
treeaa19002be5c9379b9cdba5a531263f5cf1d18ab3 /src/cmd/ld/data.c
parent592415d682232e96dda7c903d67dd24672649b76 (diff)
downloadgo-b377c9c6a9b720d0897d298652bebd3887ceeb46.tar.xz
liblink, runtime: fix cgo on arm
The addition of TLS to ARM rewrote the MRC instruction differently depending on whether we were using internal or external linking mode. That's clearly not okay, since we don't know that during compilation, which is when we now generate the code. Also, because the change did not introduce a real MRC instruction but instead just macro-expanded it in the assembler, liblink is rewriting a WORD instruction that may actually be looking for that specific constant, which would lead to very unexpected results. It was also using one value that happened to be 8 where a different value that also happened to be 8 belonged. So the code was correct for those values but not correct in general, and very confusing. Throw it all away. Replace with the following. There is a linker-provided symbol runtime.tlsgm with a value (address) set to the offset from the hardware-provided TLS base register to the g and m storage. Any reference to that name emits an appropriate TLS relocation to be resolved by either the internal linker or the external linker, depending on the link mode. The relocation has exactly the semantics of the R_ARM_TLS_LE32 relocation, which is what the external linker provides. This symbol is only used in two routines, runtime.load_gm and runtime.save_gm. In both cases it is now used like this: MRC 15, 0, R0, C13, C0, 3 // fetch TLS base pointer MOVW $runtime·tlsgm(SB), R2 ADD R2, R0 // now R0 points at thread-local g+m storage It is likely that this change breaks the generation of shared libraries on ARM, because the MOVW needs to be rewritten to use the global offset table and a different relocation type. But let's get the supported functionality working again before we worry about unsupported functionality. LGTM=dave, iant R=iant, dave CC=golang-codereviews https://golang.org/cl/56120043
Diffstat (limited to 'src/cmd/ld/data.c')
-rw-r--r--src/cmd/ld/data.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/cmd/ld/data.c b/src/cmd/ld/data.c
index 506bfd3b07..640fd6d6ef 100644
--- a/src/cmd/ld/data.c
+++ b/src/cmd/ld/data.c
@@ -167,6 +167,17 @@ relocsym(LSym *s)
diag("unknown reloc %d", r->type);
break;
case D_TLS:
+ if(linkmode == LinkInternal && iself && thechar == '5') {
+ // On ELF ARM, the thread pointer is 8 bytes before
+ // the start of the thread-local data block, so add 8
+ // to the actual TLS offset (r->sym->value).
+ // This 8 seems to be a fundamental constant of
+ // ELF on ARM (or maybe Glibc on ARM); it is not
+ // related to the fact that our own TLS storage happens
+ // to take up 8 bytes.
+ o = 8 + r->sym->value;
+ break;
+ }
r->done = 0;
o = 0;
if(thechar != '6')
@@ -879,13 +890,13 @@ dodata(void)
}
sect->len = datsize;
} else {
- // References to STLSBSS symbols may be in the binary
- // but should not be used. Give them an invalid address
- // so that any uses will fault. Using 1 instead of 0 so that
- // if used as an offset on ARM it will result in an unaligned
- // address and still cause a fault.
- for(; s != nil && s->type == STLSBSS; s = s->next)
- s->value = 1;
+ // Might be internal linking but still using cgo.
+ // In that case, the only possible STLSBSS symbol is tlsgm.
+ // Give it offset 0, because it's the only thing here.
+ if(s != nil && s->type == STLSBSS && strcmp(s->name, "runtime.tlsgm") == 0) {
+ s->value = 0;
+ s = s->next;
+ }
}
if(s != nil) {