Commit f6b9a927 authored by PoroCYon's avatar PoroCYon Committed by PoroCYon
Browse files

use _start, but don't call it ;)

parent 56357dc0
......@@ -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 $@
......@@ -20,7 +20,7 @@ header:
; e_version
dd 1
; e_entry
dd _start
dd _smol_start
; e_phoff
dd (.segments - header)
; e_shoff
......
......@@ -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 : {
......
; 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 :)
#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();
}
Supports Markdown
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