fix importing weak symbols

This commit is contained in:
PoroCYon 2019-04-02 16:58:36 +02:00 committed by PoroCYon
parent 8a4b7ce4ec
commit 8c7ce9c930
3 changed files with 16 additions and 0 deletions

View File

@ -36,6 +36,10 @@ ld -T ld/link.ld --oformat=binary -o output.elf nasm-output.o input.o...
of glibc.
* `NO_START_ARG`: *don't* pass the stack pointer to `_start` as the first arg.
Will make it unable to read argc/argv/environ, but gives you 3 bytes.
* `SKIP_ZERO_VALUE`: skip a `Sym` with a `st_value` field of `0`. If this isn't
enabled, weak symbols etc. might be imported instead of the real ones,
causing breakage. Many libraries don't have weak symbols at all, though.
Costs 4 (i386) or 5 (x86_64) bytes.
```
usage: smol.py [-h] [-m TARGET] [-l LIB] [-L DIR] [--nasm NASM] [--cc CC]

View File

@ -133,6 +133,10 @@ _smol_start:
.hasheq:
mov eax, [edx + ST_VALUE_OFF]
pop edx
%ifdef SKIP_ZERO_VALUE
or eax, eax
jz short .next_link
%endif
mov esi, [edx + L_ADDR_OFF]
;cmp eax, esi
; jb short .hasheqnorel

View File

@ -127,6 +127,10 @@ _smol_start:
.hasheq:
mov rax, [rdx + ST_VALUE_OFF]
%ifdef SKIP_ZERO_VALUE
or rax, rax
jz short .next_link
%endif
add rax, [r12 + L_ADDR_OFF]
stosq
cmp word [rdi], 0
@ -215,6 +219,10 @@ repne scasd ; technically, scasq should be used, but meh. this is 1 byte smaller
; ElfW(Addr) symoff(rax) = symtab[bucket].st_value
lea rdx, [rcx + rcx * 2]
mov rax, [rax + rdx * 8 + ST_VALUE_OFF]
%ifdef SKIP_ZERO_VALUE
or rax, rax ; zero value => weak symbol or sth
jz short .next_link
%endif
; void* finaladdr(rax) = symoff + entry->l_addr
add rax, [r12 + L_ADDR_OFF]