1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 14:17:34 +00:00

Implement loading of linked ELF executables.

This took me a couple hours. :^)

The ELF loading code now allocates a single region for the entire
file and creates virtual memory mappings for the sections as needed.

Very nice!
This commit is contained in:
Andreas Kling 2018-10-27 14:56:52 +02:00
parent 99ee6acd69
commit 9a71c7759a
16 changed files with 258 additions and 57 deletions

View file

@ -30,17 +30,17 @@ ARCH_FLAGS =
STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib
USERLAND_FLAGS = -ffreestanding -fno-stack-protector -fno-ident
WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings
FLAVOR_FLAGS = -fomit-frame-pointer -mregparm=3 -march=i386 -m32 -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -fmerge-all-constants -fno-unroll-loops -falign-functions=1 -falign-jumps=1 -falign-loops=1 -fno-pie -fno-pic
FLAVOR_FLAGS = -march=i386 -mregparm=3 -m32 -fno-exceptions -fno-rtti -fmerge-all-constants -fno-unroll-loops -fno-pie -fno-pic
OPTIMIZATION_FLAGS = -Os -fno-asynchronous-unwind-tables
INCLUDE_FLAGS = -I.. -I.
DEFINES = -DSERENITY -DSANITIZE_PTRS -DUSERLAND
CXXFLAGS = $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(USERLAND_FLAGS) $(FLAVOR_FLAGS) $(ARCH_FLAGS) $(STANDARD_FLAGS) $(INCLUDE_FLAGS) $(DEFINES)
CXX = g++
CXX = g++-8
LD = ld
AR = ar
LDFLAGS = -r -static --strip-debug -melf_i386 --build-id=none -z norelro -z now -e _start
LDFLAGS = -static --strip-debug -melf_i386 --build-id=none -z norelro -z now -e _start --gc-sections
all: $(OBJS) $(APPS)

View file

@ -1,21 +1,24 @@
#include <LibC/stdio.h>
#include <LibC/unistd.h>
#include <LibC/dirent.h>
#include <LibC/errno.h>
#include <LibC/string.h>
int main(int c, char** v)
{
DIR* dirp = opendir(".");
if (!dirp) {
printf("opendir failed :(\n");
perror("opendir failed");
return 1;
}
char pathbuf[256];
while (auto* de = readdir(dirp)) {
sprintf(pathbuf, "%s", de->d_name);
stat st;
int rc = lstat(pathbuf, &st);
if (rc == -1) {
printf("Failed to stat '%s'\n", pathbuf);
printf("lstat(%s) failed: %s\n", pathbuf, strerror(errno));
return 2;
}