Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Debugging build and test
on:
- push
- pull_request
jobs:
build:
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@v4
- name: Build (debugging mode)
run: make debug
- name: Run make check
run: make check
- name: Build regression test runner
run: make -C test/regtest
- name: Run regression test suite
run: cd test/regtest && ./regtest
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,22 @@
*.o
*.a
src/e9patch/e9loader_*.c
test/regtest/*.so
test/regtest/*.exe
test/regtest/*.log
test/regtest/*.out
test/regtest/*.diff
test/regtest/bugs
test/regtest/dl
test/regtest/fini
test/regtest/init
test/regtest/inst
test/regtest/patch
test/regtest/regtest
test/regtest/test
test/regtest/test.libc
test/regtest/test.pie
test/regtest/test_c
test/regtest/test_c.debug
/e9patch
/e9tool
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all clean install dev release debug sanitize
.PHONY: all clean check install dev release debug sanitize

#########################################################################
# BUILD COMMON
Expand Down Expand Up @@ -66,6 +66,7 @@ clean:
$(MAKE) -C contrib/zydis clean
rm -rf $(E9PATCH_OBJS) $(E9TOOL_OBJS) e9patch e9tool \
src/e9patch/e9loader_*.c e9loader_*.o e9loader_*.bin
$(MAKE) -C test/regtest clean

src/e9patch/e9loader_elf.c: src/e9patch/e9loader_elf.cpp
$(CXX) -std=c++11 -Wall -fno-stack-protector -Wno-unused-function -fPIC \
Expand All @@ -82,6 +83,9 @@ src/e9patch/e9loader_pe.c: src/e9patch/e9loader_pe.cpp
src/e9patch/e9elf.o: src/e9patch/e9loader_elf.c
src/e9patch/e9pe.o: src/e9patch/e9loader_pe.c

check: all
$(MAKE) -C test/regtest check

install: all
install -d "$(DESTDIR)$(PREFIX)/bin"
install -m 755 e9patch "$(DESTDIR)$(PREFIX)/bin/e9patch"
Expand Down
87 changes: 66 additions & 21 deletions test/regtest/Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,81 @@
.POSIX:
.PHONY: all clean check

E9TOOL ?= ../../e9tool
E9COMPILE ?= ../../e9compile.sh

FCF_NONE := $(shell \
if gcc -fcf-protection=none --version 2>&1 | grep -q 'unrecognized'; \
then true; \
else echo -fcf-protection=none; fi)

all:
gcc -x assembler-with-cpp -o test test.s -no-pie -nostdlib \
BASE ::= test test.pie bugs test.libc libtest.so test_c test_c.debug example.so
TRAMPOLINE ::= inst patch dl init fini
IN ::= $(wildcard *.in)
EXE ::= $(IN:.in=.exe)

all: regtest $(BASE) $(TRAMPOLINE)

clean:
rm -f regtest
rm -f $(BASE) $(TRAMPOLINE) $(EXE)
rm -f *.out *.log *.diff

regtest: regtest.cpp
$(CXX) -std=c++11 -O2 -g -fPIC -pie $< -o $@

%.exe: in=$(shell head -1 $<)
%.exe: %.in $(BASE) $(TRAMPOLINE) $(E9TOOL)
$(E9TOOL) $(E9TOOL_OPTIONS) -M 'addr >= &"entry"' $(in)\
-E data..data_END -E data2...text -E .text..begin -o $@

test: test.s
$(CC) -x assembler-with-cpp -o $@ $< -no-pie -nostdlib \
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
-Wl,-z -Wl,max-page-size=4096 -DPIE=0
gcc -x assembler-with-cpp -o test.pie test.s -pie -nostdlib \

test.pie: test.s
$(CC) -x assembler-with-cpp -o $@ $< -pie -nostdlib \
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
-Wl,-z -Wl,max-page-size=4096 -DPIE=1 \
-Wl,--export-dynamic
gcc -x assembler-with-cpp -o bugs bugs.s -no-pie -nostdlib \

bugs: bugs.s
$(CC) -x assembler-with-cpp -o $@ $< -no-pie -nostdlib \
-Wl,--section-start=.text=0xa000000 -Wl,--section-start=.bss=0xc000000 \
-Wl,-z -Wl,max-page-size=4096 -DPIE=0
gcc -x assembler-with-cpp -o test.libc test_libc.s -pie -Wl,--export-dynamic
gcc -x assembler-with-cpp -shared -o libtest.so libtest.s
gcc -O2 -fPIC $(FCF_NONE) -pie -o test_c test_c.c \

test.libc: test_libc.s
$(CC) -x assembler-with-cpp -pie $< -Wl,--export-dynamic -o $@

libtest.so: libtest.s
$(CC) -x assembler-with-cpp $< -shared -o $@

test_c: test_c.c
$(CC) -O2 -fPIC $(FCF_NONE) -pie -o $@ $< \
-Wl,--export-dynamic -U_FORTIFY_SOURCE
strip test_c
gcc -O0 -g -fPIC -pie -o test_c.debug test_c.c
../../e9compile.sh inst.c -I ../../examples/
../../e9compile.sh patch.cpp -std=c++11 -I ../../examples/
NO_SIMD_CHECK=1 ../../e9compile.sh dl.c -I ../../examples/
../../e9compile.sh init.c -I ../../examples/
../../e9compile.sh fini.c -I ../../examples/
g++ -std=c++11 -fPIC -shared -o example.so -O2 \
../../examples/plugins/example.cpp -I ../../src/e9tool/
g++ -std=c++11 -pie -fPIC -o regtest regtest.cpp -O2
echo "XXX" > FILE.txt
chmod 0640 FILE.txt

clean:
rm -f *.log *.out *.exe test test.pie test.libc libtest.so inst inst.o \
patch patch.o init init.o regtest
test_c.debug: test_c.c
$(CC) -O0 -g -fPIC -pie $< -o $@

inst: inst.c ../../examples/stdlib.c $(E9COMPILE)
$(E9COMPILE) $< -I../../examples

patch: patch.cpp ../../examples/stdlib.c $(E9COMPILE)
$(E9COMPILE) $< -std=c++11 -I../../examples

dl: dl.c ../../examples/stdlib.c $(E9COMPILE)
NO_SIMD_CHECK=1 $(E9COMPILE) $< -I../../examples

init: init.c ../../examples/stdlib.c $(E9COMPILE)
$(E9COMPILE) $< -I../../examples

fini: fini.c ../../examples/stdlib.c $(E9COMPILE)
$(E9COMPILE) $< -I../../examples

example.so: ../../examples/plugins/example.cpp ../../src/e9tool/e9plugin.h
$(CXX) -std=c++11 -O2 -fPIC -I../../src/e9tool $< -shared -o $@

check: run-tests $(EXE)
./$^
3 changes: 2 additions & 1 deletion test/regtest/init_dso.cmd
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
LD_PRELOAD=$PWD/init_dso.exe ./test.pie
#!/bin/sh
LD_PRELOAD=./init_dso.exe ./test.pie
3 changes: 2 additions & 1 deletion test/regtest/init_dso_2.cmd
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
LD_PRELOAD=$PWD/init_dso.exe ./test.pie a b c 1 2 3
#!/bin/sh
LD_PRELOAD=./init_dso.exe ./test.pie a b c 1 2 3
17 changes: 4 additions & 13 deletions test/regtest/regtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cstdlib>
#include <cstring>

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.h>
Expand Down Expand Up @@ -110,20 +111,10 @@ static bool runTest(const struct dirent *test, const std::string &options)
}

// Step (2): execute the EXE
FILE *CMD = fopen(cmd.c_str(), "r");
command.clear();
command += "./exec.sh ";
if (CMD != NULL)
{
for (int i = 0; (c = getc(CMD)) != '\n' && isprint(c) && i < 1024; i++)
command += c;
fclose(CMD);
}
else
{
command += "./";
command += exe;
}
command += "./exec.sh ./";
struct stat cmd_stat;
command += (stat(cmd.c_str(), &cmd_stat) == 0) ? cmd : exe;
command += " >";
command += out;
command += " 2>&1";
Expand Down
26 changes: 26 additions & 0 deletions test/regtest/run-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
fails=()
for exe in $*
do
tst=${exe%.exe}
cmd=$tst.cmd
out=$tst.out
exp=$tst.exp

if test -f $cmd
then ./exec.sh ./$cmd 1>$out 2>&1
else ./exec.sh ./$exe 1>$out 2>&1
fi
sed -i 's/ (core dumped)$//' $out

diff -u $out $exp
if test $? -ne 0
then fails+=($tst)
fi
done

if test "$fails"
then
echo "Failing ${#fails[@]}/$# tests: ${fails[@]}"
exit 1
fi
5 changes: 5 additions & 0 deletions test/regtest/stat.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
trap 'rm -f FILE.txt' EXIT HUP INT TERM
echo XXX > FILE.txt
chmod 0640 FILE.txt
./stat.exe
11 changes: 8 additions & 3 deletions test/regtest/test_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#ifndef putchar
#undef putchar
#endif

asm (
#ifndef __GNUC__
#define __asm__ asm
#endif

__asm__ (
".globl entry\n"
".set entry,0x0\n"
);
Expand Down Expand Up @@ -69,12 +74,12 @@ __attribute__((__noinline__)) void triforce(ssize_t n)
void data_func_2(void)
{
printf("invoked data_func()\n");
asm volatile ("nop");
__asm__ volatile ("nop");
}

static void data_func(void)
{
asm volatile (
__asm__ volatile (
"xchg %r15, %r15\n"
"callq data_func_2");
}
Expand Down
Loading