Commit 8c7ce9c9 authored by PoroCYon's avatar PoroCYon Committed by PoroCYon
Browse files

fix importing weak symbols

parent 8a4b7ce4
......@@ -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]
......
......@@ -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
......
......@@ -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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment