Skip to content

Commit 486c1df

Browse files
authored
Fix/aarch64 optimization relro (#3)
* Implemented improvements but real bug is not solved. * Add docker command for testing.
1 parent bb5bab6 commit 486c1df

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

.dockerignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
**
2+
!plthook_elf.c
3+
!plthook_osx.c
4+
!plthook_win32.c
5+
!plthook.h
6+
!test
7+
test/*.obj
8+
test/libtest.dll
9+
test/libtest.exp
10+
test/libtest.lib
11+
test/libtest.so
12+
test/testprog
13+
test/testprog.exe
14+
test/dummy.c
15+
test/dummy.o

Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Dockerfile for QEMU testing
2+
# docker build -t metacall/plthook .
3+
FROM ubuntu:latest
4+
5+
RUN apt update \
6+
&& apt install -y \
7+
make \
8+
qemu-user \
9+
gcc-arm-linux-gnueabi \
10+
gcc-arm-linux-gnueabihf \
11+
gcc-aarch64-linux-gnu \
12+
gcc-powerpc-linux-gnu \
13+
gcc-powerpc64le-linux-gnu \
14+
gcc-riscv64-linux-gnu \
15+
libc6-dev-armhf-cross \
16+
libc6-dev-ppc64el-cross \
17+
libc6-dev-powerpc-cross \
18+
libc6-dev-armel-cross \
19+
libc6-dev-arm64-cross
20+
21+
WORKDIR /plthook
22+
23+
COPY . .
24+
25+
WORKDIR /plthook/test
26+
27+
ENV OPT_CFLAGS="-O3"
28+
29+
RUN echo "Running tests" \
30+
&& make relro_pie_tests TARGET_PLATFORM=aarch64-linux-gnu \
31+
&& make relro_pie_tests TARGET_PLATFORM=arm-linux-gnueabi \
32+
&& make relro_pie_tests TARGET_PLATFORM=arm-linux-gnueabihf \
33+
&& make relro_pie_tests TARGET_PLATFORM=powerpc-linux-gnu QEMU_ARCH=ppc \
34+
&& make relro_pie_tests TARGET_PLATFORM=powerpc64le-linux-gnu QEMU_ARCH=ppc64le \
35+
&& make relro_pie_tests TARGET_PLATFORM=riscv64-linux-gnu QEMU_ARCH=riscv64

plthook_elf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,14 +683,14 @@ static int plthook_open_real(plthook_t **plthook_out, struct link_map *lmap)
683683
set_errmsg("failed to find PLT_DT_RELSZ");
684684
return PLTHOOK_INTERNAL_ERROR;
685685
}
686-
total_size = dyn->d_un.d_ptr;
686+
total_size = dyn->d_un.d_val;
687687

688688
dyn = find_dyn_by_tag(lmap->l_ld, PLT_DT_RELENT);
689689
if (dyn == NULL) {
690690
set_errmsg("failed to find PLT_DT_RELENT");
691691
return PLTHOOK_INTERNAL_ERROR;
692692
}
693-
elem_size = dyn->d_un.d_ptr;
693+
elem_size = dyn->d_un.d_val;
694694
plthook.rela_dyn_cnt = total_size / elem_size;
695695
}
696696
#endif

test/testprog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void reset_result(void)
9090

9191
static void set_result(hooked_val_t *hv, const char *str, double result)
9292
{
93-
strncpy(hv->str, str, sizeof(hv->str));
93+
strncpy(hv->str, str, sizeof(hv->str) - 1);
9494
hv->result = result;
9595
}
9696

0 commit comments

Comments
 (0)