-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
arc binutils generates incorrect thread local storage (TLS) offsets #688
Comments
@keith-packard so is that an issue due to misbehavior of GCC for ARC? |
No, GCC generates correct code. It's the linker which appears to write the wrong relocation value into the resulting binary. Here's the assembly output from gcc for this test:
You can see that GCC emits special symbol names like |
Ok, so then it's GNU LD which does something wrong? ;) |
Well, GNU LD works correctly on every other platform, so it's not a general issue, it's specific to the arc platform. I figured I'd start by bugging the arc toolchain people here. We'll need to track this issue in sdk-ng anyways as that will drive whether we can enable TLS in the arc targets for Zephyr. Given this bug, we should probably go disable this feature in Zephyr until it's fixed here though. |
@claziss do you have any ideas what might be wrong here with TLS? |
Do u build with this patch: |
We use -ftls-model=local-exec for Zephyr. I'm sorry I hadn't validated my little test case above with the same compiler flag. Re-checking this morning, I get the same values though. But, it does raise an interesting question about whether there are bits of this logic in the linker relocation code that might be causing this effect. As far as I can tell, this is purely a linker issue. Here's the output of
|
Hi,
Now,
Hence,
Adding everything, we get I hope this helps you. REF: https://github.com/foss-for-synopsys-dwc-arc-processors/arc-ABI-manual/blob/master/arcv3-elf.md |
It's not terribly helpful -- it doesn't explain why the computed offsets appear to be wrong in the local exec case. The docs say you take the value in gp and add the computed offset to get the address of the TLS variable and that it should work for both .tdata and .tbss symbols. There's no value I can place in gp which generates correct addresses for all four variables, and it appears to be a problem caused by the additional alignment constraints. Without those, things "just work", but when alignment is added, the offsets do not seem correct. |
Indeed, the alignment of |
@keith-packard thank you for reporting this bug. I have created a patch for it here: foss-for-synopsys-dwc-arc-processors/binutils-gdb@e7e04c7 |
I'm working on standalone arc testing for picolibc. One of the tests checks to make sure TLS offsets and relocations work correctly for values that require larger alignment. I discovered that the relocations generated in the output file don't match the positions of the values within the TLS segment. With this bug present, TLS cannot be used on arc.
I've managed to reproduce this in a stand-alone test case.
Source code:
Compile command:
objdump output:
You can see that all of the TLS variables are referenced with incorrect offsets:
If this required a computable offset to the TLS base address based on the TLS block alignment (as on ARM), that would be fixable in the linker script and/or TLS register setting code. However, the offsets of
data_var
anddata_var_128
are 0x80 while the offsets ofbss_var
andbss_var_256
are 0x100.The text was updated successfully, but these errors were encountered: