riscv-non-isa / riscv-asm-manual

RISC-V Assembly Programmer's Manual
https://jira.riscv.org/browse/RVG-4
Creative Commons Attribution 4.0 International
1.44k stars 238 forks source link

ELF question #51

Closed quantrpeter closed 4 years ago

quantrpeter commented 4 years ago

Hi What is "-0xc0" means? and where i can find this information in elf?

Disassembly of section .text:

08000240 <__clz_tab-0xc0>:
 8000240:       500a                    0x500a
 8000242:       6f72                    flw     ft10,28(sp)
 8000244:       6d617267                0x6d617267
 8000248:       6820                    flw     fs0,80(s0)

I found the symbol clz_tab, but it should start in 0x8000300, but not 0x8000240

 101: 08000300   256 OBJECT  GLOBAL HIDDEN     3 __clz_tab

thanks Peter

jim-wilson commented 4 years ago

When objdump disassembles, it looks for the nearest symbol. Sometimes the nearest symbol is a previous one in which case you get symbol+offset. Sometimes the nearest symbol is a following one, in which case you get symbol-offset. This last case is rare, but is the case you hit here. So clz_tab is 0x300, and 0300-0xc0 is 0x240 which is the address you have.

I would suspect the real problem here is that you used -D inxtead of -d. -d disassembles code. -D disassembles everything including data, so you get weird looking sections of code like what you have above because they aren't code, they are data. Disassembling them is not useful. The solution is to stop using -D. -D is only useful to experts in obscure cases, e.g. a jit compiler that has instruction templates in the data section, and you want to verify that the templates are correct. Otherwise, normally, you should not be using -D. It just confuses people.

quantrpeter commented 4 years ago

Perfect answer, thanks so much