boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

x86_64-static-plt32.after (1116B)


      1 #ifdef TCC_TARGET_X86_64
      2             /* boot2: tcc 0.9.26 only collapses PLT32→PC32 for hidden
      3                or LOCAL symbols. Under BOOTSTRAP we force static_link=1
      4                and emit no .dynamic / no PT_INTERP, so no runtime
      5                linker exists to fill in the GOT slot a PLT entry would
      6                jump through. Extend the collapse to any symbol defined
      7                in this object (st_shndx != SHN_UNDEF) so the call site
      8                becomes a direct PC-relative branch — same effect a
      9                static link gets on aarch64, where R_AARCH64_CALL26 is
     10                always resolved direct. Without this, `call main` from
     11                start.S resolves to a PLT entry whose GOT slot is never
     12                populated → jmp 0 → SIGSEGV. */
     13             if ((type == R_X86_64_PLT32 || type == R_X86_64_PC32) &&
     14                 (ELFW(ST_VISIBILITY)(sym->st_other) != STV_DEFAULT ||
     15 		 ELFW(ST_BIND)(sym->st_info) == STB_LOCAL ||
     16 		 sym->st_shndx != SHN_UNDEF)) {
     17                 rel->r_info = ELFW(R_INFO)(sym_index, R_X86_64_PC32);
     18                 continue;
     19             }
     20 #endif