Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PoroCYon
smol
Commits
f6b9a927
Commit
f6b9a927
authored
Jan 26, 2019
by
PoroCYon
Committed by
PoroCYon
Feb 27, 2019
Browse files
use _start, but don't call it ;)
parent
56357dc0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
f6b9a927
...
...
@@ -38,7 +38,7 @@ $(OBJDIR)/symbols.%.s: $(OBJDIR)/%.o.syms
$(LDRDIR)
/mksyms
$(LIBS)
$$
(
cat
$^
)
>
$@
$(OBJDIR)/header.%.o
:
$(OBJDIR)/symbols.%.s $(LDRDIR)/header.s $(LDRDIR)/loader.s
nasm
$(ASFLAGS)
$<
-o
$@
nasm
-DUSE_INTERP
$(ASFLAGS)
$<
-o
$@
$(BINDIR)/%
:
$(OBJDIR)/%.o $(OBJDIR)/header.%.o
$(LD)
-m
elf_i386
$(LDFLAGS)
$^
-o
$@
ldr/header.s
View file @
f6b9a927
...
...
@@ -20,7 +20,7 @@ header:
; e_version
dd
1
; e_entry
dd
_start
dd
_smol
_start
; e_phoff
dd
(
.
segments
-
header
)
; e_shoff
...
...
ldr/link.ld
View file @
f6b9a927
...
...
@@ -6,7 +6,9 @@ SECTIONS {
.header : { *(.header) }
.text : {
*(.text .text.* .rdata .rdata.* .rodata .rodata.*)
*(.text._smol_start)
*(.text._start)
*(.text .rdata .rdata.* .rodata .rodata.*)
}
.data : {
...
...
ldr/loader.s
View file @
f6b9a927
; vim: set ft=nasm ts=8:
[
section
.
text
]
%
define
LM_NAME_OFFSET
0x4
%
define
LM_NEXT_OFFSET
0xC
...
...
@@ -22,6 +21,8 @@
lm_off_extra
:
dd
0
[
section
.
text.
_smol_start
]
strcmp
:
; (const char *s1 (esi), const char *s2 (edi))
push
esi
push
edi
...
...
@@ -130,15 +131,15 @@ link: ; (struct link_map *root, char *symtable)
.
done
:
ret
extern
main
_start
:
extern
_start
_smol
_start
:
; try to get the 'version-agnostic' pffset of the stuff we're
; interested in
mov
ebx
,
eax
mov
esi
,
eax
.
looper
:
lodsd
cmp
dword
eax
,
_start
cmp
dword
eax
,
_smol
_start
jne
short
.
looper
sub
esi
,
ebx
sub
esi
,
LM_ENTRY_OFFSET_BASE
+
4
; +4: take inc-after from lodsb into acct
...
...
@@ -150,6 +151,6 @@ _start:
push
eax
call
link
call
main
int3
;jmp short _start
; by abusing the linker script, _start ends up right here :)
src/test.c
0 → 100644
View file @
f6b9a927
#include
<stdlib.h>
#include
<stdio.h>
const
char
*
f
=
"foo"
;
__attribute__
((
__externally_visible__
,
__section__
(
".text._start"
),
__noreturn__
))
int
_start
(
void
)
{
printf
(
"hello world %s
\n
"
,
f
);
exit
(
42
);
__builtin_unreachable
();
}
Write
Preview
Supports
Markdown
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