aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.fossil-settings/ignore-glob2
-rw-r--r--Makefile30
-rw-r--r--src/c_bsdsetsid.S24
3 files changed, 41 insertions, 15 deletions
diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob
index f43e489..b37143a 100644
--- a/.fossil-settings/ignore-glob
+++ b/.fossil-settings/ignore-glob
@@ -1,5 +1,5 @@
bsdsetsid
-.ccls
+.ccls*
.ccls-cache
.clang_complete
git
diff --git a/Makefile b/Makefile
index 7c56037..9214784 100644
--- a/Makefile
+++ b/Makefile
@@ -26,12 +26,35 @@ SRCS := ${SRCS_DIR}c_bsdsetsid.S
OBJS = ${SRCS:.S=.o}
-AS := yasm
-ASFLAGS := -felf64
+AS = yasm
+ASFLAGS = -felf64
ASFLAGS += -pgas
+ASFLAGS += -gdwarf2
+
+CC = cc
LD := ld
LDFLAGS := -melf_x86_64
+LDFLAGS += --eh-frame-hdr
+LDFLAGS += -dynamic-linker
+LDFLAGS += /libexec/ld-elf.so.1
+LDFLAGS += --hash-style=both
+LDFLAGS += --enable-new-dtags
+LDPOST := /usr/lib/crt1.o
+LDPOST += /usr/lib/crti.o
+LDPOST += /usr/lib/crtbegin.o
+LDPOST += -L/usr/lib
+LDPOST += -lgcc
+LDPOST += --as-needed
+LDPOST += -lgcc_s
+LDPOST += --no-as-needed
+LDPOST += -lc
+LDPOST += -lgcc
+LDPOST += --as-needed
+LDPOST += -lgcc_s
+LDPOST += --no-as-needed
+LDPOST += /usr/lib/crtend.o
+LDPOST += /usr/lib/crtn.o
NAME := bsdsetsid
@@ -43,7 +66,8 @@ RM := rm -f
${AS} ${ASFLAGS} -o ${.TARGET} ${.IMPSRC}
${NAME}: ${OBJS}
- ${LD} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC}
+ ${LD} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} ${LDPOST}
+ # ${CC} -v -o ${.TARGET} ${.ALLSRC}
all: ${NAME}
diff --git a/src/c_bsdsetsid.S b/src/c_bsdsetsid.S
index d9b1067..4d202dd 100644
--- a/src/c_bsdsetsid.S
+++ b/src/c_bsdsetsid.S
@@ -1,19 +1,21 @@
-.data
-str:
- .asciz "a string\n"
-
.text
-.globl _start
-
-_start:
- jmp c_main
+.globl main
c_main:
movq $0x1, %rdi
leaq str, %rsi
- movq $0x9, %rdx
- movq $0x4, %rax
+ movq $0xa, %rdx
+ movb $0x4, %al
syscall
+ retq
+
+main:
+ xorq %rax, %rax
+ callq c_main
+ xorq %rax, %rax
xorq %rdi, %rdi
- movq $0x1, %rax
+ movb $0x1, %al
syscall
+
+.data
+ str: .asciz "a string\n"