The-Z-Labs / bof-launcher

Beacon Object File (BOF) launcher - library for executing BOF files in C/C++/Zig applications
BSD 3-Clause "New" or "Revised" License
136 stars 14 forks source link

Unhandled relocations in ARM (EABI5) objects #6

Closed dsnezhkov closed 1 month ago

dsnezhkov commented 1 month ago

Hi guys,

Similar to parts of Issue5, looks like a couple of unhandled relocations for a generic ARM EABI5 object on ARMV7l (HF) when compiled with gcc (see zig cc below which runs ok.

Build: zig build -Doptimize=Debug -Dtarget=arm-linux-gnueabihf.

Note: I modified the build.zig to remove the .cpu_model restriction:

        .{
            .cpu_arch = .arm,
            .os_tag = .linux,
            .abi = .gnueabihf,
        }, 
$ ../../zig-out/bin/integration_with_c_lin_arm uname.o
<bof-filename>: uname.o
File size is: 1248
debug: Number of Sections: 12
debug: Section Index: 0
debug:  Name is 0
debug:  Flags are 0x0
debug:  Type is 0x0
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0x0
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 1
debug:  Name is 31
debug:  Flags are 0x6
debug:  Type is 0x1
debug:  Size is 176
debug:  EntSize is 0
debug:  Offset is 0x34
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 2
debug:  Name is 27
debug:  Flags are 0x40
debug:  Type is 0x9
debug:  Size is 88
debug:  EntSize is 8
debug:  Offset is 0x244
debug:  Addr is 0x0
debug:  Link is 9
debug:  Info is 1
debug:      Case Not Handled
debug: Section Index: 3
debug:  Name is 37
debug:  Flags are 0x3
debug:  Type is 0x1
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0xe4
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 4
debug:  Name is 43
debug:  Flags are 0x3
debug:  Type is 0x8
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0xe4
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 5
debug:  Name is 48
debug:  Flags are 0x2
debug:  Type is 0x1
debug:  Size is 38
debug:  EntSize is 0
debug:  Offset is 0xe4
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 6
debug:  Name is 56
debug:  Flags are 0x30
debug:  Type is 0x1
debug:  Size is 32
debug:  EntSize is 1
debug:  Offset is 0x10a
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 7
debug:  Name is 65
debug:  Flags are 0x0
debug:  Type is 0x1
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0x12a
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 8
debug:  Name is 81
debug:  Flags are 0x0
debug:  Type is 0x70000003
debug:  Size is 51
debug:  EntSize is 0
debug:  Offset is 0x12a
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 9
debug:  Name is 1
debug:  Flags are 0x0
debug:  Type is 0x2
debug:  Size is 192
debug:  EntSize is 16
debug:  Offset is 0x160
debug:  Addr is 0x0
debug:  Link is 10
debug:  Info is 7
debug:      Symbol Table
debug:      String Table: $d$tbannerputsgounameprintf
debug: Section Index: 10
debug:  Name is 9
debug:  Flags are 0x0
debug:  Type is 0x3
debug:  Size is 35
debug:  EntSize is 0
debug:  Offset is 0x220
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      String Table: $d$tbannerputsgounameprintf
debug: Section Index: 11
debug:  Name is 17
debug:  Flags are 0x0
debug:  Type is 0x3
debug:  Size is 97
debug:  EntSize is 0
debug:  Offset is 0x29c
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      String Table: .symtab.strtab.shstrtab.rel.text.data.bss.rodata.comment.note.GNU-stack.ARM.attributes
debug:  Section type: SHT_REL
debug:  ENTRIES (Section Index: 2)
debug:      Symbol: puts
debug:      Reloc type: 10
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0x80a
debug:      Offset: 0xa
debug:      Addend: 0x-10801
debug:      addr_p: 0xb6d7000a
debug:      addr_s: 0x0
Trace/breakpoint trap
gcc -c -fno-stack-protector -fPIC uname.c -o uname.o
objcopy --strip-unneeded uname.o
$ readelf -a uname.o
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          768 (bytes into file)
  Flags:                             0x5000000, Version5 EABI
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         12
  Section header string table index: 11

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 0000b0 00  AX  0   0  4
  [ 2] .rel.text         REL             00000000 000244 000058 08   I  9   1  4
  [ 3] .data             PROGBITS        00000000 0000e4 000000 00  WA  0   0  1
  [ 4] .bss              NOBITS          00000000 0000e4 000000 00  WA  0   0  1
  [ 5] .rodata           PROGBITS        00000000 0000e4 000026 00   A  0   0  4
  [ 6] .comment          PROGBITS        00000000 00010a 000020 01  MS  0   0  1
  [ 7] .note.GNU-stack   PROGBITS        00000000 00012a 000000 00      0   0  1
  [ 8] .ARM.attributes   ARM_ATTRIBUTES  00000000 00012a 000033 00      0   0  1
  [ 9] .symtab           SYMTAB          00000000 000160 0000c0 10     10   7  4
  [10] .strtab           STRTAB          00000000 000220 000023 00      0   0  1
  [11] .shstrtab         STRTAB          00000000 00029c 000061 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),
  D (mbind), y (purecode), p (processor specific)

There are no section groups in this file.

There are no program headers in this file.

There is no dynamic section in this file.

Relocation section '.rel.text' at offset 0x244 contains 11 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0000000a  0000080a R_ARM_THM_CALL    00000000   puts
00000014  00000103 R_ARM_REL32       00000000   .rodata
00000038  00000a0a R_ARM_THM_CALL    00000000   uname
00000052  00000b0a R_ARM_THM_CALL    00000000   printf
0000005e  0000070a R_ARM_THM_CALL    00000001   banner
00000068  0000080a R_ARM_THM_CALL    00000000   puts
00000074  0000080a R_ARM_THM_CALL    00000000   puts
00000080  0000080a R_ARM_THM_CALL    00000000   puts
0000008c  0000080a R_ARM_THM_CALL    00000000   puts
0000009a  0000080a R_ARM_THM_CALL    00000000   puts
000000ac  00000103 R_ARM_REL32       00000000   .rodata

There are no unwind sections in this file.

Symbol table '.symtab' contains 12 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 SECTION LOCAL  DEFAULT    5 .rodata
     2: 00000000     0 NOTYPE  LOCAL  DEFAULT    5 $d
     3: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 $t
     4: 00000014     0 NOTYPE  LOCAL  DEFAULT    1 $d
     5: 00000018     0 NOTYPE  LOCAL  DEFAULT    1 $t
     6: 000000ac     0 NOTYPE  LOCAL  DEFAULT    1 $d
     7: 00000001    24 FUNC    GLOBAL DEFAULT    1 banner
     8: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND puts
     9: 00000019   152 FUNC    GLOBAL DEFAULT    1 go
    10: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND uname
    11: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND printf

No version information found in this file.
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "7-A"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv3-D16
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_VFP_args: VFP registers
  Tag_ABI_optimization_goals: Aggressive Debug
  Tag_CPU_unaligned_access: v6

Thank you!

dsnezhkov commented 1 month ago

I was not sure whyTrace/breakpoint trap SIGTRAP is generated, probably a specific compiler inserting it on stack trashing. Just in case, here is the zig cc version of uname.o compilation.

zig cc RUNS ok.

$ readelf -a uname.o
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              REL (Relocatable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x0
  Start of program headers:          0 (bytes into file)
  Start of section headers:          1236 (bytes into file)
  Flags:                             0x5000400, Version5 EABI, hard-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           0 (bytes)
  Number of program headers:         0
  Size of section headers:           40 (bytes)
  Number of section headers:         14
  Section header string table index: 13

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 000034 0000f4 00  AX  0   0  4
  [ 2] .rel.text         REL             00000000 0003a4 000080 08   I 11   1  4
  [ 3] .ARM.exidx        ARM_EXIDX       00000000 000128 000010 00  AL  1   0  4
  [ 4] .rel.ARM.exidx    REL             00000000 000424 000028 08   I 11   3  4
  [ 5] .ARM.extab        PROGBITS        00000000 000138 00000c 00   A  0   0  4
  [ 6] .rodata.str1.1    PROGBITS        00000000 000144 000028 01 AMS  0   0  1
  [ 7] .comment          PROGBITS        00000000 00016c 00006a 01  MS  0   0  1
  [ 8] .ARM.attributes   ARM_ATTRIBUTES  00000000 0001d6 000054 00      0   0  1
  [ 9] .llvm_addrsig     LOOS+0xfff4c03  00000000 00022a 000003 00   E  0   0  1
  [10] .note.GNU-stack   PROGBITS        00000000 00022d 000000 00      0   0  1
  [11] .symtab           SYMTAB          00000000 000230 000100 10     12  10  4
  [12] .strtab           STRTAB          00000000 000330 000073 00      0   0  1
  [13] .shstrtab         STRTAB          00000000 00044c 000085 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),
  D (mbind), y (purecode), p (processor specific)

There are no section groups in this file.

There are no program headers in this file.

There is no dynamic section in this file.

Relocation section '.rel.text' at offset 0x3a4 contains 16 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000010  00000b1c R_ARM_CALL        00000000   printf
00000018  00000303 R_ARM_REL32       0000001a   .L.str
00000034  00000e1c R_ARM_CALL        00000000   uname
00000054  00000b1c R_ARM_CALL        00000000   printf
00000064  00000a1c R_ARM_CALL        00000000   banner
00000074  00000b1c R_ARM_CALL        00000000   printf
00000088  00000b1c R_ARM_CALL        00000000   printf
0000009c  00000b1c R_ARM_CALL        00000000   printf
000000b0  00000b1c R_ARM_CALL        00000000   printf
000000c4  00000b1c R_ARM_CALL        00000000   printf
000000dc  00000603 R_ARM_REL32       00000016   .L.str.2
000000e0  00000603 R_ARM_REL32       00000016   .L.str.2
000000e4  00000603 R_ARM_REL32       00000016   .L.str.2
000000e8  00000603 R_ARM_REL32       00000016   .L.str.2
000000ec  00000603 R_ARM_REL32       00000016   .L.str.2
000000f0  00000703 R_ARM_REL32       00000000   .L.str.1

Relocation section '.rel.ARM.exidx' at offset 0x424 contains 5 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  00000c00 R_ARM_NONE        00000000   __aeabi_unwind_cpp_pr0
00000000  0000082a R_ARM_PREL31      00000000   .text
00000008  00000f00 R_ARM_NONE        00000000   __aeabi_unwind_cpp_pr1
00000008  0000082a R_ARM_PREL31      00000000   .text
0000000c  0000092a R_ARM_PREL31      00000000   .ARM.extab

Unwind section '.ARM.exidx' at offset 0x128 contains 2 entries:

0x0: 0x809b8480
  Compact model index: 0
  0x9b      vsp = r11
  0x84 0x80 pop {r11, r14}

0x1c <go>: @0x0
  Compact model index: 1
  0x9b      vsp = r11
  0x41      vsp = vsp - 8
  0x84 0x83 pop {r4, r5, r11, r14}
  0xb0      finish
  0xb0      finish

Symbol table '.symtab' contains 16 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000     0 NOTYPE  LOCAL  DEFAULT    1 $a.0
     2: 00000018     0 NOTYPE  LOCAL  DEFAULT    1 $d.1
     3: 0000001a    14 OBJECT  LOCAL  DEFAULT    6 .L.str
     4: 0000001c     0 NOTYPE  LOCAL  DEFAULT    1 $a.2
     5: 000000dc     0 NOTYPE  LOCAL  DEFAULT    1 $d.3
     6: 00000016     4 OBJECT  LOCAL  DEFAULT    6 .L.str.2
     7: 00000000    22 OBJECT  LOCAL  DEFAULT    6 .L.str.1
     8: 00000000     0 SECTION LOCAL  DEFAULT    1 .text
     9: 00000000     0 SECTION LOCAL  DEFAULT    5 .ARM.extab
    10: 00000000    28 FUNC    GLOBAL DEFAULT    1 banner
    11: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND printf
    12: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __aeabi_unwind_c[...]
    13: 0000001c   216 FUNC    GLOBAL DEFAULT    1 go
    14: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND uname
    15: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __aeabi_unwind_c[...]

No version information found in this file.
Attribute Section: aeabi
File Attributes
  Tag_conformance: "2.09"
  Tag_CPU_name: "cortex-a15"
  Tag_CPU_arch: v7
  Tag_CPU_arch_profile: Application
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv4
  Tag_Advanced_SIMD_arch: NEONv1 with Fused-MAC
  Tag_ABI_PCS_R9_use: V6
  Tag_ABI_PCS_RW_data: PC-relative
  Tag_ABI_PCS_RO_data: PC-relative
  Tag_ABI_PCS_GOT_use: GOT-indirect
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Unused
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_VFP_args: VFP registers
  Tag_ABI_optimization_goals: Aggressive Debug
  Tag_CPU_unaligned_access: v6
  Tag_FP_HP_extension: Allowed
  Tag_ABI_FP_16bit_format: IEEE 754
  Tag_MPextension_use: Allowed
  Tag_DIV_use: Allowed in v7-A with integer division extension
  Tag_Virtualization_use: TrustZone and Virtualization Extensions
$ ../../zig-out/bin/integration_with_c_lin_arm uname.o
<bof-filename>: uname.o
File size is: 1796
debug: Number of Sections: 14
debug: Section Index: 0
debug:  Name is 0
debug:  Flags are 0x0
debug:  Type is 0x0
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0x0
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 1
debug:  Name is 31
debug:  Flags are 0x6
debug:  Type is 0x1
debug:  Size is 244
debug:  EntSize is 0
debug:  Offset is 0x34
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 2
debug:  Name is 27
debug:  Flags are 0x40
debug:  Type is 0x9
debug:  Size is 128
debug:  EntSize is 8
debug:  Offset is 0x3a4
debug:  Addr is 0x0
debug:  Link is 11
debug:  Info is 1
debug:      Case Not Handled
debug: Section Index: 3
debug:  Name is 41
debug:  Flags are 0x82
debug:  Type is 0x70000001
debug:  Size is 16
debug:  EntSize is 0
debug:  Offset is 0x128
debug:  Addr is 0x0
debug:  Link is 1
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 4
debug:  Name is 37
debug:  Flags are 0x40
debug:  Type is 0x9
debug:  Size is 40
debug:  EntSize is 8
debug:  Offset is 0x424
debug:  Addr is 0x0
debug:  Link is 11
debug:  Info is 3
debug:      Case Not Handled
debug: Section Index: 5
debug:  Name is 52
debug:  Flags are 0x2
debug:  Type is 0x1
debug:  Size is 12
debug:  EntSize is 0
debug:  Offset is 0x138
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 6
debug:  Name is 63
debug:  Flags are 0x32
debug:  Type is 0x1
debug:  Size is 40
debug:  EntSize is 1
debug:  Offset is 0x144
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 7
debug:  Name is 78
debug:  Flags are 0x30
debug:  Type is 0x1
debug:  Size is 106
debug:  EntSize is 1
debug:  Offset is 0x16c
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 8
debug:  Name is 87
debug:  Flags are 0x0
debug:  Type is 0x70000003
debug:  Size is 84
debug:  EntSize is 0
debug:  Offset is 0x1d6
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 9
debug:  Name is 103
debug:  Flags are 0x80000000
debug:  Type is 0x6fff4c03
debug:  Size is 3
debug:  EntSize is 0
debug:  Offset is 0x22a
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 10
debug:  Name is 117
debug:  Flags are 0x0
debug:  Type is 0x1
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0x22d
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 11
debug:  Name is 1
debug:  Flags are 0x0
debug:  Type is 0x2
debug:  Size is 256
debug:  EntSize is 16
debug:  Offset is 0x230
debug:  Addr is 0x0
debug:  Link is 12
debug:  Info is 10
debug:      Symbol Table
debug:      String Table: $a.0$d.1.L.str$a.2$d.3.L.str.2.L.str.1bannerprintf__aeabi_unwind_cpp_pr0gouname__aeabi_unwind_cpp_pr1
debug: Section Index: 12
debug:  Name is 9
debug:  Flags are 0x0
debug:  Type is 0x3
debug:  Size is 115
debug:  EntSize is 0
debug:  Offset is 0x330
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      String Table: $a.0$d.1.L.str$a.2$d.3.L.str.2.L.str.1bannerprintf__aeabi_unwind_cpp_pr0gouname__aeabi_unwind_cpp_pr1
debug: Section Index: 13
debug:  Name is 17
debug:  Flags are 0x0
debug:  Type is 0x3
debug:  Size is 133
debug:  EntSize is 0
debug:  Offset is 0x44c
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      String Table: .symtab.strtab.shstrtab.rel.text.rel.ARM.exidx.ARM.extab.rodata.str1.1.comment.ARM.attributes.llvm_addrsig.note.GNU-stack
debug:  Section type: SHT_REL
debug:  ENTRIES (Section Index: 2)
debug:      Symbol: printf
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xb1c
debug:      Offset: 0x10
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e00010
debug:      addr_s: 0x0
debug:      -------------------------------------------------
debug:      Symbol: .L.str
debug:      Reloc type: 3
debug:      Symbol Value: 0x1a
debug:      Shndx: 0x6
debug:      Info: 0x303
debug:      Offset: 0x18
debug:      Addend: 0x4
debug:      addr_p: 0xb6e00018
debug:      addr_s: 0xb6e1801a
debug:      -------------------------------------------------
debug:      Symbol: uname
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xe1c
debug:      Offset: 0x34
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e00034
debug:      addr_s: 0x0
debug:      -------------------------------------------------
debug:      Symbol: printf
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xb1c
debug:      Offset: 0x54
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e00054
debug:      addr_s: 0x0
debug:      -------------------------------------------------
debug:      Symbol: banner
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x1
debug:      Info: 0xa1c
debug:      Offset: 0x64
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e00064
debug:      addr_s: 0xb6e00000
debug:      -------------------------------------------------
debug:      Symbol: printf
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xb1c
debug:      Offset: 0x74
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e00074
debug:      addr_s: 0x0
debug:      -------------------------------------------------
debug:      Symbol: printf
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xb1c
debug:      Offset: 0x88
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e00088
debug:      addr_s: 0x0
debug:      -------------------------------------------------
debug:      Symbol: printf
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xb1c
debug:      Offset: 0x9c
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e0009c
debug:      addr_s: 0x0
debug:      -------------------------------------------------
debug:      Symbol: printf
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xb1c
debug:      Offset: 0xb0
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e000b0
debug:      addr_s: 0x0
debug:      -------------------------------------------------
debug:      Symbol: printf
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xb1c
debug:      Offset: 0xc4
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e000c4
debug:      addr_s: 0x0
debug:      -------------------------------------------------
debug:      Symbol: .L.str.2
debug:      Reloc type: 3
debug:      Symbol Value: 0x16
debug:      Shndx: 0x6
debug:      Info: 0x603
debug:      Offset: 0xdc
debug:      Addend: 0x14
debug:      addr_p: 0xb6e000dc
debug:      addr_s: 0xb6e18016
debug:      -------------------------------------------------
debug:      Symbol: .L.str.2
debug:      Reloc type: 3
debug:      Symbol Value: 0x16
debug:      Shndx: 0x6
debug:      Info: 0x603
debug:      Offset: 0xe0
debug:      Addend: 0x2c
debug:      addr_p: 0xb6e000e0
debug:      addr_s: 0xb6e18016
debug:      -------------------------------------------------
debug:      Symbol: .L.str.2
debug:      Reloc type: 3
debug:      Symbol Value: 0x16
debug:      Shndx: 0x6
debug:      Info: 0x603
debug:      Offset: 0xe4
debug:      Addend: 0x44
debug:      addr_p: 0xb6e000e4
debug:      addr_s: 0xb6e18016
debug:      -------------------------------------------------
debug:      Symbol: .L.str.2
debug:      Reloc type: 3
debug:      Symbol Value: 0x16
debug:      Shndx: 0x6
debug:      Info: 0x603
debug:      Offset: 0xe8
debug:      Addend: 0x5c
debug:      addr_p: 0xb6e000e8
debug:      addr_s: 0xb6e18016
debug:      -------------------------------------------------
debug:      Symbol: .L.str.2
debug:      Reloc type: 3
debug:      Symbol Value: 0x16
debug:      Shndx: 0x6
debug:      Info: 0x603
debug:      Offset: 0xec
debug:      Addend: 0x74
debug:      addr_p: 0xb6e000ec
debug:      addr_s: 0xb6e18016
debug:      -------------------------------------------------
debug:      Symbol: .L.str.1
debug:      Reloc type: 3
debug:      Symbol Value: 0x0
debug:      Shndx: 0x6
debug:      Info: 0x703
debug:      Offset: 0xf0
debug:      Addend: 0x98
debug:      addr_p: 0xb6e000f0
debug:      addr_s: 0xb6e18000
debug:      -------------------------------------------------
debug:  Section type: SHT_REL
debug:  ENTRIES (Section Index: 4)
debug:      Symbol: __aeabi_unwind_cpp_pr0
debug:      Reloc type: 0
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xc00
debug:      Offset: 0x0
debug:      Addend: 0x0
debug:      addr_p: 0xb6e08000
debug:      addr_s: 0x0
debug: Unhandled ARM ELF relocation (0)
debug:      -------------------------------------------------
debug:      Symbol:
debug:      Reloc type: 42
debug:      Symbol Value: 0x0
debug:      Shndx: 0x1
debug:      Info: 0x82a
debug:      Offset: 0x0
debug:      Addend: 0x0
debug:      addr_p: 0xb6e08000
debug:      addr_s: 0xb6e00000
debug:      -------------------------------------------------
debug:      Symbol: __aeabi_unwind_cpp_pr1
debug:      Reloc type: 0
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xf00
debug:      Offset: 0x8
debug:      Addend: 0x1c
debug:      addr_p: 0xb6e08008
debug:      addr_s: 0x0
debug: Unhandled ARM ELF relocation (0)
debug:      -------------------------------------------------
debug:      Symbol:
debug:      Reloc type: 42
debug:      Symbol Value: 0x0
debug:      Shndx: 0x1
debug:      Info: 0x82a
debug:      Offset: 0x8
debug:      Addend: 0x1c
debug:      addr_p: 0xb6e08008
debug:      addr_s: 0xb6e00000
debug:      -------------------------------------------------
debug:      Symbol:
debug:      Reloc type: 42
debug:      Symbol Value: 0x0
debug:      Shndx: 0x5
debug:      Info: 0x92a
debug:      Offset: 0xc
debug:      Addend: 0x0
debug:      addr_p: 0xb6e0800c
debug:      addr_s: 0xb6e10000
debug:      -------------------------------------------------
debug: SYMBOLS
debug:  Name: $a.0                                               Address(real): 0xb6e00000
debug:  Name: $d.1                                               Address(real): 0xb6e00018
debug:  Name: .L.str                                             Address(real): 0xb6e1801a
debug:  Name: $a.2                                               Address(real): 0xb6e0001c
debug:  Name: $d.3                                               Address(real): 0xb6e000dc
debug:  Name: .L.str.2                                           Address(real): 0xb6e18016
debug:  Name: .L.str.1                                           Address(real): 0xb6e18000
debug:  Name:                                                    Address(real): 0xb6e00000
debug:  Name:                                                    Address(real): 0xb6e10000
debug:  Name: banner                                             Address(real): 0xb6e00000
debug:  Name: go                                                 Address(real): 0xb6e0001c
debug: go() FOUND.
Running BOF from command line C application...
debug: Trying to run go()...
=== Uname ==
Linux
deb-armhf
6.1.0-25-armmp-lpae
#1 SMP Debian 6.1.106-3 (2024-08-26)
armv7l
debug: Returned '0' from go().
dsnezhkov commented 1 month ago

Update: the trace/breakpoint trap seems to be coming from assert: https://github.com/The-Z-Labs/bof-launcher/blob/5383b3ac846755307f48a132992546ec1ea884d8/bof-launcher/src/bof_launcher.zig#L733

Instrumented around it:

debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 10. Expecting 28 or 29
Trace/breakpoint trap
dsnezhkov commented 1 month ago

uname.o (gcc) uname.gcc-arm.zip

dsnezhkov commented 1 month ago

Compiling uname.o with gcc -O2 -c -fno-exceptions -fno-stack-protector -fPIC uname.c -o uname.o changes the (order of?) relocation types it first encounters.

debug:      -------------------------------------------------
debug:      Symbol: puts
debug:      Reloc type: 30
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0x91e
debug:      Offset: 0x4
debug:      Addend: 0x-40010801
debug:      addr_p: 0xb6e34004
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 30. Expecting 28 or 29
Trace/breakpoint trap
Relocation section '.rel.text' at offset 0x210 contains 11 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
00000008  00000203 R_ARM_REL32            00000000   .LC0
00000014  00000b0a R_ARM_THM_CALL         00000000   uname
0000001c  0000080a R_ARM_THM_CALL         00000001   banner
00000022  0000090a R_ARM_THM_CALL         00000000   puts
0000002a  0000090a R_ARM_THM_CALL         00000000   puts
00000032  0000090a R_ARM_THM_CALL         00000000   puts
0000003a  0000090a R_ARM_THM_CALL         00000000   puts
00000040  0000090a R_ARM_THM_CALL         00000000   puts
00000050  00000c0a R_ARM_THM_CALL         00000000   printf
0000005c  00000503 R_ARM_REL32            00000010   .LC1
00000004  0000091e R_ARM_THM_JUMP24       00000000   puts

Relocations:

10 | R_ARM_THM_CALL | Static | Thumb32 | ((S + A) \| T) – P
30 | R_ARM_THM_JUMP24 | Static | Thumb32 | ((S + A) \| T) – P
dsnezhkov commented 1 month ago

Maybe the cpu picked up by gcc and zig cc are different to warrant Thumb2 vs. pure ARM instruction set? So, adding -marm to compilation looks like it executes as well. Looking at the following - curious is this what you'd suggest doing going forward - forcing compliance with R_ARM_CALL and avoiding Thumb2?

gcc -marm -c -fno-stack-protector -fPIC uname.c -o uname.o

Relocation section '.rel.text' at offset 0x26c contains 11 entries:
 Offset     Info    Type                Sym. Value  Symbol's Name
00000014  0000081c R_ARM_CALL             00000000   puts
00000020  00000103 R_ARM_REL32            00000000   .rodata
00000040  00000a1c R_ARM_CALL             00000000   uname
00000064  00000b1c R_ARM_CALL             00000000   printf
00000074  0000071c R_ARM_CALL             00000000   banner
00000080  0000081c R_ARM_CALL             00000000   puts
00000090  0000081c R_ARM_CALL             00000000   puts
000000a0  0000081c R_ARM_CALL             00000000   puts
000000b0  0000081c R_ARM_CALL             00000000   puts
000000c0  0000081c R_ARM_CALL             00000000   puts
000000d4  00000103 R_ARM_REL32            00000000   .rodata
$ ../../zig-out/bin/integration_with_c_lin_arm ./uname.o
<bof-filename>: ./uname.o
File size is: 1288
debug: Number of Sections: 12
debug: Section Index: 0
debug:  Name is 0
debug:  Flags are 0x0
debug:  Type is 0x0
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0x0
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 1
debug:  Name is 31
debug:  Flags are 0x6
debug:  Type is 0x1
debug:  Size is 216
debug:  EntSize is 0
debug:  Offset is 0x34
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 2
debug:  Name is 27
debug:  Flags are 0x40
debug:  Type is 0x9
debug:  Size is 88
debug:  EntSize is 8
debug:  Offset is 0x26c
debug:  Addr is 0x0
debug:  Link is 9
debug:  Info is 1
debug:      Case Not Handled
debug: Section Index: 3
debug:  Name is 37
debug:  Flags are 0x3
debug:  Type is 0x1
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0x10c
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 4
debug:  Name is 43
debug:  Flags are 0x3
debug:  Type is 0x8
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0x10c
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 5
debug:  Name is 48
debug:  Flags are 0x2
debug:  Type is 0x1
debug:  Size is 38
debug:  EntSize is 0
debug:  Offset is 0x10c
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 6
debug:  Name is 56
debug:  Flags are 0x30
debug:  Type is 0x1
debug:  Size is 32
debug:  EntSize is 1
debug:  Offset is 0x132
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 7
debug:  Name is 65
debug:  Flags are 0x0
debug:  Type is 0x1
debug:  Size is 0
debug:  EntSize is 0
debug:  Offset is 0x152
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 8
debug:  Name is 81
debug:  Flags are 0x0
debug:  Type is 0x70000003
debug:  Size is 51
debug:  EntSize is 0
debug:  Offset is 0x152
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      Case Not Handled
debug: Section Index: 9
debug:  Name is 1
debug:  Flags are 0x0
debug:  Type is 0x2
debug:  Size is 192
debug:  EntSize is 16
debug:  Offset is 0x188
debug:  Addr is 0x0
debug:  Link is 10
debug:  Info is 7
debug:      Symbol Table
debug:      String Table: $d$abannerputsgounameprintf
debug: Section Index: 10
debug:  Name is 9
debug:  Flags are 0x0
debug:  Type is 0x3
debug:  Size is 35
debug:  EntSize is 0
debug:  Offset is 0x248
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      String Table: $d$abannerputsgounameprintf
debug: Section Index: 11
debug:  Name is 17
debug:  Flags are 0x0
debug:  Type is 0x3
debug:  Size is 97
debug:  EntSize is 0
debug:  Offset is 0x2c4
debug:  Addr is 0x0
debug:  Link is 0
debug:  Info is 0
debug:      String Table: .symtab.strtab.shstrtab.rel.text.data.bss.rodata.comment.note.GNU-stack.ARM.attributes
debug:  Section type: SHT_REL
debug:  ENTRIES (Section Index: 2)
debug:      Symbol: puts
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0x81c
debug:      Offset: 0x14
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e22014
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 28. Expecting 28 or 29
debug: arm: Post-R_ARM_CALL check
debug:      -------------------------------------------------
debug:      Symbol:
debug:      Reloc type: 3
debug:      Symbol Value: 0x0
debug:      Shndx: 0x5
debug:      Info: 0x103
debug:      Offset: 0x20
debug:      Addend: 0xc
debug:      addr_p: 0xb6e22020
debug:      addr_s: 0xb6e2a000
debug:      -------------------------------------------------
debug:      Symbol: uname
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xa1c
debug:      Offset: 0x40
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e22040
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 28. Expecting 28 or 29
debug: arm: Post-R_ARM_CALL check
debug:      -------------------------------------------------
debug:      Symbol: printf
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0xb1c
debug:      Offset: 0x64
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e22064
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 28. Expecting 28 or 29
debug: arm: Post-R_ARM_CALL check
debug:      -------------------------------------------------
debug:      Symbol: banner
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x1
debug:      Info: 0x71c
debug:      Offset: 0x74
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e22074
debug:      addr_s: 0xb6e22000
debug:      -------------------------------------------------
debug:      Symbol: puts
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0x81c
debug:      Offset: 0x80
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e22080
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 28. Expecting 28 or 29
debug: arm: Post-R_ARM_CALL check
debug:      -------------------------------------------------
debug:      Symbol: puts
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0x81c
debug:      Offset: 0x90
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e22090
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 28. Expecting 28 or 29
debug: arm: Post-R_ARM_CALL check
debug:      -------------------------------------------------
debug:      Symbol: puts
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0x81c
debug:      Offset: 0xa0
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e220a0
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 28. Expecting 28 or 29
debug: arm: Post-R_ARM_CALL check
debug:      -------------------------------------------------
debug:      Symbol: puts
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0x81c
debug:      Offset: 0xb0
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e220b0
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 28. Expecting 28 or 29
debug: arm: Post-R_ARM_CALL check
debug:      -------------------------------------------------
debug:      Symbol: puts
debug:      Reloc type: 28
debug:      Symbol Value: 0x0
debug:      Shndx: 0x0
debug:      Info: 0x81c
debug:      Offset: 0xc0
debug:      Addend: 0x-14000002
debug:      addr_p: 0xb6e220c0
debug:      addr_s: 0x0
debug: arm: Pre-R_ARM_CALL check
debug: arm: Seeing reloc.r_type(): 28. Expecting 28 or 29
debug: arm: Post-R_ARM_CALL check
debug:      -------------------------------------------------
debug:      Symbol:
debug:      Reloc type: 3
debug:      Symbol Value: 0x0
debug:      Shndx: 0x5
debug:      Info: 0x103
debug:      Offset: 0xd4
debug:      Addend: 0x80
debug:      addr_p: 0xb6e220d4
debug:      addr_s: 0xb6e2a000
debug:      -------------------------------------------------
debug: SYMBOLS
debug:  Name:                                                    Address(real): 0xb6e2a000
debug:  Name: $d                                                 Address(real): 0xb6e2a000
debug:  Name: $a                                                 Address(real): 0xb6e22000
debug:  Name: $d                                                 Address(real): 0xb6e22020
debug:  Name: $a                                                 Address(real): 0xb6e22024
debug:  Name: $d                                                 Address(real): 0xb6e220d4
debug:  Name: banner                                             Address(real): 0xb6e22000
debug:  Name: go                                                 Address(real): 0xb6e22024
debug: go() FOUND.
Running BOF from command line C application...
debug: Trying to run go()...
=== Uname ==
Linux
deb-armhf
6.1.0-25-armmp-lpae
#1 SMP Debian 6.1.106-3 (2024-08-26)
armv7l
debug: Returned '0' from go().
michal-z commented 1 month ago

Thanks for the report.

We don't currently support Thumb so going with pure ARM32 would be a way forward.

We didn't plan to add support for Thumb but please let me know if this is something you would be interested in.

dsnezhkov commented 1 month ago

Thank you, makes sense.I guess our path on ARM (and maybe others in time) may need to be SOC / dependent, and we'll need to look closely at what the compiler is dong to the object. Hopefully, not too much different from identifying the initial quirks like these flags. Extensive debugs help a lot, and I appreciate you instrumenting the relo code.