Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
smol
Commits
8c7ce9c9
Commit
8c7ce9c9
authored
Apr 02, 2019
by
PoroCYon
Committed by
PoroCYon
Apr 29, 2019
Browse files
fix importing weak symbols
parent
8a4b7ce4
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
8c7ce9c9
...
@@ -36,6 +36,10 @@ ld -T ld/link.ld --oformat=binary -o output.elf nasm-output.o input.o...
...
@@ -36,6 +36,10 @@ ld -T ld/link.ld --oformat=binary -o output.elf nasm-output.o input.o...
of glibc.
of glibc.
*
`NO_START_ARG`
:
*don't*
pass the stack pointer to
`_start`
as the first arg.
*
`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.
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]
usage: smol.py [-h] [-m TARGET] [-l LIB] [-L DIR] [--nasm NASM] [--cc CC]
...
...
rt/loader32.asm
View file @
8c7ce9c9
...
@@ -133,6 +133,10 @@ _smol_start:
...
@@ -133,6 +133,10 @@ _smol_start:
.hasheq:
.hasheq:
mov
eax
,
[
edx
+
ST_VALUE_OFF
]
mov
eax
,
[
edx
+
ST_VALUE_OFF
]
pop
edx
pop
edx
%ifdef SKIP_ZERO_VALUE
or
eax
,
eax
jz
short
.next_link
%endif
mov
esi
,
[
edx
+
L_ADDR_OFF
]
mov
esi
,
[
edx
+
L_ADDR_OFF
]
;cmp eax, esi
;cmp eax, esi
; jb short .hasheqnorel
; jb short .hasheqnorel
...
...
rt/loader64.asm
View file @
8c7ce9c9
...
@@ -127,6 +127,10 @@ _smol_start:
...
@@ -127,6 +127,10 @@ _smol_start:
.hasheq:
.hasheq:
mov
rax
,
[
rdx
+
ST_VALUE_OFF
]
mov
rax
,
[
rdx
+
ST_VALUE_OFF
]
%ifdef SKIP_ZERO_VALUE
or
rax
,
rax
jz
short
.next_link
%endif
add
rax
,
[
r12
+
L_ADDR_OFF
]
add
rax
,
[
r12
+
L_ADDR_OFF
]
stosq
stosq
cmp
word
[
rdi
],
0
cmp
word
[
rdi
],
0
...
@@ -215,6 +219,10 @@ repne scasd ; technically, scasq should be used, but meh. this is 1 byte smaller
...
@@ -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
; ElfW(Addr) symoff(rax) = symtab[bucket].st_value
lea
rdx
,
[
rcx
+
rcx
*
2
]
lea
rdx
,
[
rcx
+
rcx
*
2
]
mov
rax
,
[
rax
+
rdx
*
8
+
ST_VALUE_OFF
]
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
; void* finaladdr(rax) = symoff + entry->l_addr
add
rax
,
[
r12
+
L_ADDR_OFF
]
add
rax
,
[
r12
+
L_ADDR_OFF
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment