aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-04-06 19:46:41 -0400
committerIan Moffett <ian@osmora.org>2024-04-06 19:48:10 -0400
commit8370d0a3eb373c37386de32ccd3a8a38ddeb8b02 (patch)
tree2f390a0f8206c8dca80362dd49b01ef3ecec1fc2 /lib
parenteccaaf54d8e5ab90ed0cf9dd3be8204e35115692 (diff)
build: Statically link libc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/Makefile19
-rw-r--r--lib/libc/src/arch/amd64/crt0.S (renamed from lib/libc/linker/entry.S)6
-rw-r--r--lib/libc/src/main.c (renamed from lib/libc/linker/entry.c)26
3 files changed, 18 insertions, 33 deletions
diff --git a/lib/libc/Makefile b/lib/libc/Makefile
index fabb532..76a5359 100644
--- a/lib/libc/Makefile
+++ b/lib/libc/Makefile
@@ -5,14 +5,17 @@ LIBC_ASMFILES = $(shell find src/ -name "*.S")
LIBC_OBJ = $(LIBC_CFILES:.c=.o)
LIBC_ASMOBJ = $(LIBC_ASMFILES:.S=.S.o)
-all: $(LIBC_OBJ) build/ld.so
-
-build/ld.so: build/ linker/entry.c linker/entry.S
- mkdir -p $(@D)
- $(CC) $(CFLAGS) linker/entry.S -o build/entry.S.o
- $(CC) $(CFLAGS) linker/entry.c -o build/entry.o
- $(LD) -znoexecstack $(LIBC_OBJ) \
- build/entry.o build/entry.S.o -o $@
+all: $(LIBC_ASMOBJ) $(LIBC_OBJ) build/libc.a
+
+build/libc.a: build/
+ ar rcs build/libc.a $(LIBC_OBJ) $(LIBC_ASMOBJ)
+
+#build/ld.so: build/ linker/entry.c linker/entry.S
+# mkdir -p $(@D)
+# $(CC) $(CFLAGS) linker/entry.S -o build/entry.S.o
+# $(CC) $(CFLAGS) linker/entry.c -o build/entry.o
+# $(LD) -znoexecstack $(LIBC_OBJ) \
+# build/entry.o build/entry.S.o -o $@
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
diff --git a/lib/libc/linker/entry.S b/lib/libc/src/arch/amd64/crt0.S
index 1f982f9..17dddc6 100644
--- a/lib/libc/linker/entry.S
+++ b/lib/libc/src/arch/amd64/crt0.S
@@ -33,15 +33,15 @@
#include <sys/syscall.h>
-.section .text, "ax", @progbits
+.text
.globl _start
_start:
// Mark end of callstack
xor %rbp, %rbp
- // Load process context as per the sysv AMD64 ABI
+ // Load process context and call entry
lea (%rsp), %rdi
- call entry
+ call __libc_entry
// We are done, now we exit
mov $SYS_exit, %rax
diff --git a/lib/libc/linker/entry.c b/lib/libc/src/main.c
index 55bf312..477842b 100644
--- a/lib/libc/linker/entry.c
+++ b/lib/libc/src/main.c
@@ -27,34 +27,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/syscall.h>
-#include <sys/auxv.h>
#include <stdint.h>
-#include <stddef.h>
-#include <elf.h>
-#if !defined(__hyra__)
-#error "Hyra supported only"
-#endif
+int main(int argc, const char **argv, const char **envp);
-void
-entry(const uint64_t *ctx)
+int
+__libc_entry(uint64_t *ctx)
{
uint64_t argc = *ctx;
- uint64_t auxv[AT_MAX_COUNT] = {0};
- int envc;
-
const char **argv = (const char **)(ctx + 1);
const char **envp = (const char **)(argv + argc + 1);
- struct auxv_entry *auxvp;
-
- /* Read-in auxiliary vector */
- auxvp = (struct auxv_entry *)(envp + envc + 1);
- for (; auxvp->tag != AT_NULL; ++auxvp) {
- if (auxvp->tag < AT_MAX_COUNT) {
- auxv[auxvp->tag] = auxvp->val;
- }
- }
- /* TODO */
+ return main(argc, argv, envp);
}