[Libre-soc-bugs] [Bug 1169] Add ELF and mmap support to ISACaller -- no dynamic linking

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Wed Sep 20 01:58:05 BST 2023


https://bugs.libre-soc.org/show_bug.cgi?id=1169

--- Comment #3 from Jacob Lifshay <programmerjake at gmail.com> ---
(In reply to Jacob Lifshay from comment #2)
> iirc during the meeting luke suggested using an elf decoding library, icr
> what was suggested, so I did some searching and I think pyelftools might be
> best, it's pure python.
> 
> https://github.com/eliben/pyelftools

it seems to work well.

Because just using -static doesn't remove all relocations, I used this test
program:
#include <sys/syscall.h>

long syscall(long number, ...);

// too bad powerpc64le doesn't support __attribute__((naked))
asm(
    ".globl syscall\n"
    ".p2align 4\n"
    ".type syscall, at function\n"
    "syscall:\n"
    "mr 0,3\n"
    "mr 3,4\n"
    "mr 4,5\n"
    "mr 5,6\n"
    "mr 6,7\n"
    "mr 7,8\n"
    "mr 8,9\n"
    "sc\n"
    "blr"
);

void _start() {
    static char v = 'H';
    char msg[] = " ello!";
    msg[sizeof(msg) - 1] = '\n';
    msg[0] = v;
    syscall(SYS_write, 1, (const void *)msg, sizeof(msg));
    syscall(SYS_exit_group, 0);
}

I compiled it with:
clang -O3 -ffreestanding -fno-pic -fno-pie -nostdlib -static prog.c

then ran:
readelf.py -e -r a.out

<snip>
Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000010000000 0x0000000010000000
                 0x0000000000000214 0x0000000000000214  R E    10000
  LOAD           0x0000000000000218 0x0000000010010218 0x0000000010010218
                 0x0000000000000001 0x0000000000000001  RW     10000
  NOTE           0x0000000000000120 0x0000000010000120 0x0000000010000120
                 0x0000000000000024 0x0000000000000024  R      4
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     10

 Section to Segment mapping:
  Segment Sections...
   00     .note.gnu.build-id .text .rodata 
   01     .data 
   02     .note.gnu.build-id 
   03     

There are no relocations in this file.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list