-
Notifications
You must be signed in to change notification settings - Fork 141
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
Failed to load code: bad relocation type 1 #18
Comments
Could you show your C code? Lines 185 to 188 in 2e06fd4
|
It looks to me like the type 1 relocations are labels from my loops? Or maybe it's the internal function? Not sure. If you would, tell me a more about this, point me to some docs, etc. I may attempt to fix it.
|
Could be your |
There may be issues with the internal functions, but I don't think that's the issue I'm seeing now. It seems to be the read-only section...
compiles down to this...
When I remove the '1' from the initializer list, then the code doesn't have the .rodata section and it works. So that list of .rodata is a type 1 relocation? |
You could check out the libbpf (https://github.com/libbpf/libbpf) project, which comes from the Linux kernel but is dual-licensed with BSD 2-clause and LGPL. |
Something doesn't match here. lllvm defines only 2 relocation types for EBPF: See: llvm/BinaryFormat/ELFRelocs/BPF.def Where does the type 2 in the code come from? Likewise a dump of a eBPF program using readelf shows:
|
I would be great if we could somehow disallow clang to emit a BPF relocation type 1 instruction. I'm trying to figure out what generates generates these relocations. So far I have found out that global variables .text section accesses generate the Some things to help debugging I found are:
I have also changed between several versions of the clang compiler (3.8, 6, 10) and tried changing the options up, unfortunately I haven't been able to prevent the generation of these instructions so far. Instead of the regular UPDATE Declaring global variables as static prevents the emitting of this |
This occurs with strings as well, e.g. if I have something like the following:
The string data goes into the rodata section. |
If you want to add support for strings, you could build in this commit 4e192c3. It adds support for emit_string_load and emitting a string table at the end of the generated machine code. |
I am not using an Intel architecture, so that commit doesn't help. I am also not using JIT (because I am using a non-Intel architecture). I'll take a look and see if I can figure out how to add support for what I need and propose a PR. Thanks for the info though! |
A workaround is this:
Produces:
Which has no relocations. |
That's very helpful, thanks very much! |
Having much the same issue, when building code with CLang-10, with the flags '-O2 -target bpf'.
When I build with CLang and include the call to bpftrace_log, I get the following relocations in my elf object.
However when the call to bpftrace_log is omitted, these disappear and all is well - no more errors from ubpf.
The bit I am missing is that CLang seems to emit 2 relocation types for ebpf, neither of which have a relocation type of 2?
So why is ubpf expecting a relocation type of 2?
|
There exists a patch in the wild that addresses this, I haven't tested it: |
Yeah - this pretty much what I had written and was testing. |
@Dantali0n so on reflection, what made me nervous about that approach, was that I wasn't certain it would cover every permutation of what Clang might produce. After thinking about it again, I think a much better approach would be to provide a Makefile and a simple example code, and say this is what we support, it then becomes a bounded problem. @reubenhwk and @pchaigno - what do you think? I can do the work, if people like the idea. |
I coded a fix supports both Clang code/function and string relocations, without breaking existing relocations. All the existing nosetests work as before. |
I compiled llvm + clang 3.9.1, and I compiled my sample like this...
~/local/bin/clang -target bpf -c src/benchmark/factor.c -o factor.o
and I get this error...
Failed to load code: bad relocation type 1
What does this mean, and how do I fix this?
The text was updated successfully, but these errors were encountered: