Skip to content
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

llvm-objcopy: "error: invalid symbol index" with mips64el-linux-gnuabi64 #52647

Closed
nathanchance opened this issue Dec 13, 2021 · 4 comments
Closed

Comments

@nathanchance
Copy link
Member

Initial reported and triaged at ClangBuiltLinux/linux#1534.

While building the Linux kernel with OBJCOPY=llvm-objcopy, the following error is observed:

llvm-objcopy: error: invalid symbol index: 67108864
make: *** [Makefile:1161: vmlinux] Error 1

This appears to be related to the use of -EL and -mabi=64. A very simple C reproducer:

$ cat test.c
void lkdtm_rodata_do_nothing() {}

$ clang --target=mips64el-linux-gnuabi64 -c test.c

$ llvm-objcopy test.o test_objcopy.o
llvm-objcopy: error: invalid symbol index: 33554432

It does not happen with mips64-linux-gnuabi64 or 32-bit MIPS targets.

@jh7370
Copy link
Collaborator

jh7370 commented Dec 13, 2021

I think the problem is in initRelocations in the llvm-objcopy code: it has references to Rel.getType(false) and Rel.getSymbol(false). The latter in particular is likely the culprit, but both are probably wrong, based on my reading of this bug: the boolean corresponds to an isMips64EL, which I'd expect to be true for the test case.

The fix will be to pass this information to these functions, and quite possibly other functions in the code (I see a reference to getSymbolAndType in writeRel that also has a suspicious hard-coded false).

Unfortunately, my MIPS knowledge is limited, so I don't know how to get the proper value for the isMips64EL parameter from the object into llvm-objcopy. As such, I cannot provide a fix myself.

@atanasyan
Copy link
Collaborator

I will take a look at this bug.

@atanasyan
Copy link
Collaborator

The fix is in the https://reviews.llvm.org/D115635.

atanasyan added a commit that referenced this issue Dec 14, 2021
MIPS64 little endian target has a "special" encoding of `r_info`
relocation record field. Instead of one 64-bit little endian number, it
is a little endian 32-bit number followed by a 32-bit big endian number.
For correct reading and writing such fields we must provide information
about target machine into the corresponding routine. This patch does
this for the `llvm-objcopy` tool and fix handling of MIPS64 little
endian files.

The bug was reported in the issue #52647.

Differential Revision: https://reviews.llvm.org/D115635
@nathanchance
Copy link
Member Author

Thanks Simon!

d5d8b1c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants