[PATCH] D139097: [ARM] Fix Address value difference for symbol emitted by llvm-nm

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 07:21:43 PST 2022


peter.smith added a comment.

Which version of nm are you using? The `arm-none-eabi-nm` from the Arm GNU toolchain (at least in my GCC toolchain) strips off the bottom bit of Thumb `STT_FUNC` like llvm-nm. The x86_64 version does not and prints the value with the bottom bit set. As such I think that llvm-nm for Arm targets should match `arm-non-eabi-nm`. I guess if there is a way to pass a triple to llvm-nm that is non-Arm then it shouldn't strip the bottom bit.

The ABI has a section on symbol values https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#553symbol-values

  In addition to the normal rules for symbol values the following rules shall also apply to symbols of type STT_FUNC:
  
  * If the symbol addresses an Arm instruction, its value is the address of the instruction (in a relocatable object, the offset of the instruction from the start of the section containing it).
  * If the symbol addresses a Thumb instruction, its value is the address of the instruction with bit zero set (in a relocatable object, the section offset with bit zero set). For the purposes of relocation the value used shall be the address of the instruction (st_value & ~1).
  
  Note
  
  This allows a linker to distinguish Arm and Thumb code symbols without having to refer to the map. An Arm symbol will always have an even value, while a Thumb symbol will always have an odd value. However, a linker should strip the discriminating bit from the value before using it for relocation.

The raw value of a Thumb address of type `STT_FUNC` will always have the bottom bit set, although its address will be `(st_value & ~1)`. I don't think the ABI gives a definitive answer to what `nm` should print. I guess it depends if llvm-nm should display the address or the raw value. In any case I think we should follow arm-none-eabi-nm.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139097/new/

https://reviews.llvm.org/D139097



More information about the llvm-commits mailing list