Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef void (*fptr)(void);
- void func1(void) {}
- void func2(void) {}
- const fptr table[] = {
- func1,
- func2,
- };
- int _start(int i)
- {
- table[i]();
- }
- -------------------------------------------------------------------------------
- $ riscv64-unknown-elf-gcc -nostdlib -nostartfiles -T linker.ld -fPIE -static-pie simple.c
- $ riscv64-unknown-elf-readelf -a a.out -W
- ELF Header:
- Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
- Class: ELF64
- Data: 2's complement, little endian
- Version: 1 (current)
- OS/ABI: UNIX - System V
- ABI Version: 0
- Type: EXEC (Executable file)
- Machine: RISC-V
- Version: 0x1
- Entry point address: 0x1038
- Start of program headers: 64 (bytes into file)
- Start of section headers: 4584 (bytes into file)
- Flags: 0x2, single-float ABI
- Size of this header: 64 (bytes)
- Size of program headers: 56 (bytes)
- Number of program headers: 1
- Size of section headers: 64 (bytes)
- Number of section headers: 7
- Section header string table index: 6
- Section Headers:
- [Nr] Name Type Address Off Size ES Flg Lk Inf Al
- [ 0] NULL 0000000000000000 000000 000000 00 0 0 0
- [ 1] .text PROGBITS 0000000000001000 001000 000084 00 AX 0 0 4
- [ 2] .data.rel.ro.local PROGBITS 0000000000001088 001088 000010 00 WA 0 0 8
- [ 3] .comment PROGBITS 0000000000000000 001098 000011 01 MS 0 0 1
- [ 4] .symtab SYMTAB 0000000000000000 0010b0 0000d8 18 5 5 8
- [ 5] .strtab STRTAB 0000000000000000 001188 000023 00 0 0 1
- [ 6] .shstrtab STRTAB 0000000000000000 0011ab 00003d 00 0 0 1
- Key to Flags:
- W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
- L (link order), O (extra OS processing required), G (group), T (TLS),
- C (compressed), x (unknown), o (OS specific), E (exclude),
- p (processor specific)
- There are no section groups in this file.
- Program Headers:
- Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
- LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000098 0x000098 RWE 0x1000
- Section to Segment mapping:
- Segment Sections...
- 00 .text .data.rel.ro.local
- There is no dynamic section in this file.
- There are no relocations in this file.
- The decoding of unwind sections for machine type RISC-V is not currently supported.
- Symbol table '.symtab' contains 9 entries:
- Num: Value Size Type Bind Vis Ndx Name
- 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
- 1: 0000000000001000 0 SECTION LOCAL DEFAULT 1
- 2: 0000000000001088 0 SECTION LOCAL DEFAULT 2
- 3: 0000000000000000 0 SECTION LOCAL DEFAULT 3
- 4: 0000000000000000 0 FILE LOCAL DEFAULT ABS simple.c
- 5: 0000000000001088 16 OBJECT GLOBAL DEFAULT 2 table
- 6: 0000000000001000 28 FUNC GLOBAL DEFAULT 1 func1
- 7: 0000000000001038 76 FUNC GLOBAL DEFAULT 1 _start
- 8: 000000000000101c 28 FUNC GLOBAL DEFAULT 1 func2
- No version information found in this file.
- $ riscv64-unknown-elf-readelf -r a.out -W
- There are no relocations in this file.
- $ riscv64-unknown-elf-objdump -r -D -S a.out
- 1050: 00000717 auipc a4,0x0
- 1054: 03870713 addi a4,a4,56 # 1088 <table>
- 1058: fec42783 lw a5,-20(s0)
- 105c: 00379793 slli a5,a5,0x3
- 1060: 00f707b3 add a5,a4,a5
- 1064: 0007b783 ld a5,0(a5)
- 1068: 000780e7 jalr a5
- Disassembly of section .data.rel.ro.local:
- 0000000000001088 <table>:
- 1088: 1000 addi s0,sp,32
- 108a: 0000 unimp
- 108c: 0000 unimp
- 108e: 0000 unimp
- 1090: 101c addi a5,sp,32
- 1092: 0000 unimp
- 1094: 0000 unimp
- ...
- -------------------------------------------------------------------------------
- $ riscv64-unknown-elf-gcc -g3 -nostdlib -nostartfiles -T linker.ld -fPIE -static-pie -c simple.c
- $ riscv64-unknown-elf-readelf -r simple.o -W
- Relocation section '.rela.text' at offset 0x6108 contains 4 entries:
- Offset Info Type Symbol's Value Symbol's Name + Addend
- 0000000000000050 0000018100000017 R_RISCV_PCREL_HI20 0000000000000000 table + 0
- 0000000000000050 0000000000000033 R_RISCV_RELAX 0
- 0000000000000054 0000001e00000018 R_RISCV_PCREL_LO12_I 0000000000000050 .L0 + 0
- 0000000000000054 0000000000000033 R_RISCV_RELAX 0
- Relocation section '.rela.data.rel.ro.local' at offset 0x6168 contains 2 entries:
- Offset Info Type Symbol's Value Symbol's Name + Addend
- 0000000000000000 0000017f00000002 R_RISCV_64 0000000000000000 func1 + 0
- 0000000000000008 0000018000000002 R_RISCV_64 000000000000001c func2 + 0
- $ riscv64-unknown-elf-objdump -r -D -S simple.o
- 0000000000000050 <.L0 >:
- table[i]();
- 50: 00000717 auipc a4,0x0
- 50: R_RISCV_PCREL_HI20 table
- 50: R_RISCV_RELAX *ABS*
- 54: 00070713 mv a4,a4
- 54: R_RISCV_PCREL_LO12_I .L0
- 54: R_RISCV_RELAX *ABS*
- 58: fec42783 lw a5,-20(s0)
- 5c: 00379793 slli a5,a5,0x3
- 60: 00f707b3 add a5,a4,a5
- 64: 0007b783 ld a5,0(a5)
- 0000000000000068 <.L0 >:
- 68: 000780e7 jalr a5
- Disassembly of section .data.rel.ro.local:
- 0000000000000000 <table>:
- ...
- 0: R_RISCV_64 func1
- 8: R_RISCV_64 func2
- --------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement