As is indexes above SHN_LORESERVE will not be handled correctly because they'll be treated as indexes of sections rather than special values that should just be copied. This change adds support to copy them though.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
tools/llvm-objcopy/Object.cpp | ||
---|---|---|
236–242 | This fails to handle SHN_XINDEX correctly. See its handling elsewhere in the code base, or read the ELF spec. It's probably OK to just pass all other >= SHN_LORESERVE values through blindly, but I'm not sure it's the best idea. |
- Followed Roland's recomendation and throw an error on SHN_XINDEX and I only support specific values. If an unsupported value is used llvm-objcopy should now throw an error.
I'm not closely familiar with this code base, so it should probably still get some review from someone who has reviewed the objcopy implementation so far.
But just looking at the apparent logic in this change, it looks OK to me with the caveats noted below.
tools/llvm-objcopy/Object.cpp | ||
---|---|---|
200 | This seems an oddly general-sounding name for this. | |
239 | It's >=, not >. | |
tools/llvm-objcopy/Object.h | ||
119 | Since this is currently not actually the section index per se, I'd prefer not to call it that. |
In addition to the already-added SHN_ABS test, could we please have a test for at least SHN_COMMON, and possibly the hexagon values as well.
tools/llvm-objcopy/Object.h | ||
---|---|---|
119 | As the Symbol has a reference to the corresponding section via "DefinedIn", I don't think we need to have separate fields for a section index and the st_shndx value. Indeed, with exception of the special indexes, we don't need the section index here at all. Therefore, I think it might make more sense to have a little enum that can be converted from and to, which only supports the special values we support (plus a "normal symbol" value). It would then be the responsibility of finalize and the caller of addSymbol to map between the two values. |
- Fixed function name to be isValidReservedSectionIndex
- Changed message to correctly indicate that it should be >= and not >
- Switched to using an enum style solution. I added a method, getShndx that figures out what the correct value of st_shndx should be. I also switched how addSymbol works to account for this.
- Added requested tests
test/tools/llvm-objcopy/section-index-unsupported.test | ||
---|---|---|
3 | I think we should also check the error message here. | |
tools/llvm-objcopy/Object.cpp | ||
93 | uint32_t -> uint16_t (to match st_shndx size). | |
123 | I think this should have an llvm_unreachable clause at the end. | |
tools/llvm-objcopy/Object.h | ||
136–137 | SectionIndex -> Shndx. It should also be a uint16_t, since that is the st_shndx field size. |
LGTM, with the two minor changes I've suggested inline.
test/tools/llvm-objcopy/section-index-unsupported.test | ||
---|---|---|
16 | I don't think you need the "[[_:.*]]". The check doesn't need to match the whole line. | |
tools/llvm-objcopy/Object.cpp | ||
110 | As the if returns, I think the LLVM style is to not have the "else" here - it just becomes the rest of the function. |
I think we should also check the error message here.