Skip to content

Commit

Permalink
* refactor project tree
Browse files Browse the repository at this point in the history
* use single makefile on both platforms
  • Loading branch information
blu committed Sep 13, 2021
1 parent a19a2fa commit 8337565
Show file tree
Hide file tree
Showing 32 changed files with 150 additions and 93 deletions.
69 changes: 36 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
SRC := reloc.c reloc_add_aarch64.c insn.h stringx.s strlen_linux.s vma.cpp vma.h
# Elven Relativism top makefile for Linux/aarch64 and macOS/arm64

UNAME := $(shell uname)
UNAME_M := $(shell uname -m)
TARGET := elvenrel
SOURCE := reloc.c reloc_add_aarch64.c insn.h
CFLAGS += -std=gnu11 -Ofast -DNDEBUG -DPAGE_SIZE=$(shell getconf PAGE_SIZE) -fno-stack-protector -fPIC
CXXFLAGS += -std=c++11 -Ofast -fno-exceptions -fno-rtti -DNDEBUG -DPAGE_SIZE=$(shell getconf PAGE_SIZE) -fno-stack-protector -fPIC

ifeq ($(UNAME), Linux)

ifneq ($(UNAME_M), aarch64)
$(error unsupported arch)
endif

# Update state for linux/aarch64
SOURCE += stringx.s strlen_linux.s vma.cpp vma.h
LDFLAGS += -lelf
ASFLAGS += --strip-local-absolute
# Optional test objects built by target ALL
REL := test_text.o \
test_rodata.o \
test_data.o \
test_bss.o \
test_cross_0.o \
test_cross_1.o \
test_bounce.o \
test_bounce_neon.o \
test_bounce_neon_aosoa.o \
test_bounce_neon_aosoa_bg.o \
test_bounce_data_aosoa_alt_0.o \
test_bounce_data_aosoa_alt_1.o \
test_bounce_data_aosoa_alt_2.o \
test_bounce_data_aosoa_alt_3.o

OBJ := $(addsuffix .o, $(basename $(filter %.s %.c %.cpp, $(SRC))))
TEST_SUBDIR := test_linux

else ifeq ($(UNAME), Darwin)

ifneq ($(UNAME_M), arm64)
$(error unsupported arch)
endif

# Update state for macos/arm64
CFLAGS += -I/opt/homebrew/include
LDFLAGS += /opt/homebrew/lib/libelf.a
TEST_SUBDIR := test_macos

else # unsupported os
$(error unsupposrted os)
endif

OBJ := $(addsuffix .o, $(basename $(filter %.s %.c %.cpp, $(SOURCE))))

$(TARGET): $(OBJ)
$(CC) $^ $(LDFLAGS) -o $(TARGET)
Expand All @@ -31,19 +44,9 @@ reloc_add_aarch64.o: reloc_add_aarch64.c insn.h

vma.o: vma.cpp vma.h char_ptr_arr.h

test_bounce.o: test_bounce.s
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=1024 -o $@ $^

test_bounce_neon.o: test_bounce_neon.s
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=2048 -o $@ $^

test_bounce_neon_aosoa.o: test_bounce_neon_aosoa.s
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=1024 -o $@ $^

test_bounce_neon_aosoa_bg.o: test_bounce_neon_aosoa_bg.s
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=2048 -o $@ $^

all: $(TARGET) $(REL)
all: $(TARGET)
$(MAKE) -C $(TEST_SUBDIR) all

clean:
rm -f $(TARGET) $(OBJ) $(REL)
rm -f $(TARGET) $(OBJ)
$(MAKE) -C $(TEST_SUBDIR) clean
38 changes: 0 additions & 38 deletions Makefile.macos

This file was deleted.

20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@ Files used, with or without modifications, from external repositories:
linux.org/ arch/arm64/kernel/module.c -> reloc_add_aarch64.c
linux.org/ arch/arm64/lib/strlen.S -> strlen_linux.s

## Building: linux
## Building

$ make all

## Building: macos
## Building with own assembler

$ make -f Makefile.macos all
For instance, if you have `gas` on macos and prefer to use that:

$ make AS=full-path-to-gas all

Building `gas` itself from source:

$ git clone git://sourceware.org/git/binutils-gdb.git && cd binutils-gdb
$ cd bfd
$ ./configure --target=aarch64-linux-gnu && make && cd -
$ cd libiberty
$ ./configure --target=aarch64-linux-gnu && make && cd -
$ cd opcodes
$ ./configure --target=aarch64-linux-gnu && make && cd -
$ cd gas
$ ./configure --target=aarch64-linux-gnu && make && cd -

## Usage

Expand Down
15 changes: 0 additions & 15 deletions test_bounce_neon_aosoa.sh

This file was deleted.

32 changes: 32 additions & 0 deletions test_linux/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ASFLAGS += --strip-local-absolute
REL := test_text.o \
test_rodata.o \
test_data.o \
test_bss.o \
test_cross_0.o \
test_cross_1.o \
test_bounce.o \
test_bounce_neon.o \
test_bounce_neon_aosoa.o \
test_bounce_neon_aosoa_bg.o \
test_bounce_data_aosoa_alt_0.o \
test_bounce_data_aosoa_alt_1.o \
test_bounce_data_aosoa_alt_2.o \
test_bounce_data_aosoa_alt_3.o

test_bounce.o: test_bounce.s
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=1024 -o $@ $^

test_bounce_neon.o: test_bounce_neon.s
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=2048 -o $@ $^

test_bounce_neon_aosoa.o: test_bounce_neon_aosoa.s
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=1024 -o $@ $^

test_bounce_neon_aosoa_bg.o: test_bounce_neon_aosoa_bg.s
$(AS) $(ASFLAGS) --defsym FB_DIM_X=$(shell tput cols) --defsym FB_DIM_Y=$(shell tput lines) --defsym FRAMES=2048 -o $@ $^

all: $(REL)

clean:
rm -f $(REL)
File renamed without changes.
5 changes: 3 additions & 2 deletions test_bounce.sh → test_linux/test_bounce.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash
BUILD=..

make all
make -C ${BUILD} all

# Hide term cursor before loading REL; nuke all VMAs from common libraries and
# the process heap VMA, before passing control to _start; restore term cursor
# upon termination

tput civis
./elvenrel test_bounce.o --filter /lib/aarch64-linux-gnu --filter [heap]
${BUILD}/elvenrel test_bounce.o --filter /lib/aarch64-linux-gnu --filter [heap]
tput cnorm
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions test_linux/test_bounce_neon_aosoa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
BUILD=..

make -C ${BUILD} all

# Hide term cursor before loading RELs; nuke all VMAs from common libraries and
# the process heap VMA, before passing control to _start; suppress reports to
# stdout; restore term cursor upon termination

tput civis
${BUILD}/elvenrel test_bounce_data_aosoa_alt_0.o test_bounce_neon_aosoa.o --filter /lib/aarch64-linux-gnu --filter [heap] --quiet
${BUILD}/elvenrel test_bounce_data_aosoa_alt_1.o test_bounce_neon_aosoa.o --filter /lib/aarch64-linux-gnu --filter [heap] --quiet
${BUILD}/elvenrel test_bounce_data_aosoa_alt_2.o test_bounce_neon_aosoa.o --filter /lib/aarch64-linux-gnu --filter [heap] --quiet
${BUILD}/elvenrel test_bounce_data_aosoa_alt_3.o test_bounce_neon_aosoa.o --filter /lib/aarch64-linux-gnu --filter [heap] --quiet
${BUILD}/elvenrel test_bounce_data_aosoa_alt_2.o test_bounce_neon_aosoa_bg.o --filter /lib/aarch64-linux-gnu --filter [heap] --quiet
tput cnorm
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions test_cross.sh → test_linux/test_cross.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
BUILD=..

make all
make -C ${BUILD} all

# Load two RELs with cross-relocations; nuke all VMAs from common libraries and
# the process heap VMA, before passing control to _start

./elvenrel test_cross_0.o test_cross_1.o --filter /lib/aarch64-linux-gnu --filter [heap]
${BUILD}/elvenrel test_cross_0.o test_cross_1.o --filter /lib/aarch64-linux-gnu --filter [heap]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions test_macos/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Support both GAS and Apple clang
AS_VENDOR := $(word 1, $(shell $(AS) --version))
ifeq ($(AS_VENDOR), GNU)
ASFLAGS += --strip-local-absolute
defsym = --defsym $(1)=$(2)
else
ASFLAGS += --target=aarch64-linux-gnu
defsym = -Wa,-defsym,$(1)=$(2)
endif
REL := test_text.o \
test_rodata.o \
test_data.o \
test_bss.o \
test_cross_0.o \
test_cross_1.o \
test_bounce.o

test_bounce.o: test_bounce.s
$(AS) $(ASFLAGS) $(call defsym,FB_DIM_X,$(shell tput cols)) $(call defsym,FB_DIM_Y,$(shell tput lines)) $(call defsym,FRAMES,1024) -o $@ $^

all: $(REL)

clean:
rm -f $(REL)
File renamed without changes.
11 changes: 11 additions & 0 deletions test_macos/test_bounce.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
BUILD=..

make -C ${BUILD} all

# Hide term cursor before loading REL; restore term cursor
# upon termination

tput civis
${BUILD}/elvenrel test_bounce.o
tput cnorm
File renamed without changes.
8 changes: 8 additions & 0 deletions test_macos/test_cross.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
BUILD=..

make -C ${BUILD} all

# Load two RELs with cross-relocations

${BUILD}/elvenrel test_cross_0.o test_cross_1.o
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8337565

Please sign in to comment.