Skip to content

Commit 5c4dfb5

Browse files
committed
Issues from aarch solved and loongarch64 support kubo#55 (comment) thanks to @zllang
1 parent 8c97587 commit 5c4dfb5

File tree

9 files changed

+43
-20
lines changed

9 files changed

+43
-20
lines changed

.github/workflows/run-tests.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ jobs:
6767
./uclibc-test.sh i686
6868
6969
tests_on_qemu:
70-
name: Tests on Qemu (arm, armhf, arm64, ppc, ppc64le and riscv64)
70+
name: Tests on Qemu (arm, armhf, arm64, ppc, ppc64le, riscv64, s390x and loongarch64)
7171
if: github.event.inputs.tests_on_qemu == 'true' || github.event.inputs.tests_on_qemu == ''
7272
strategy:
7373
fail-fast: false
7474
matrix:
7575
optimization: ["", "-O2", "-O3"]
76-
# TODO: Sanitizer fails in armhf and aarch64
77-
# sanitize: ["", "-g -fsanitize=address -fsanitize=undefined"]
76+
sanitize: ["", "-g -fsanitize=address -fsanitize=undefined"]
7877
runs-on: ubuntu-latest
7978
defaults:
8079
run:
@@ -84,12 +83,10 @@ jobs:
8483
- name: Install packages
8584
run: |
8685
sudo apt update
87-
sudo apt install -y qemu-user gcc-arm-linux-gnueabi gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-powerpc-linux-gnu gcc-powerpc64le-linux-gnu gcc-riscv64-linux-gnu gcc-s390x-linux-gnu libc6-dev-armhf-cross libc6-dev-ppc64el-cross libc6-dev-powerpc-cross libc6-dev-armel-cross libc6-dev-arm64-cross libc6-dev-s390x-cross
86+
sudo apt install -y qemu-user gcc-arm-linux-gnueabi gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu gcc-powerpc-linux-gnu gcc-powerpc64le-linux-gnu gcc-riscv64-linux-gnu gcc-s390x-linux-gnu gcc-14-loongarch64-linux-gnu libc6-dev-armhf-cross libc6-dev-ppc64el-cross libc6-dev-powerpc-cross libc6-dev-armel-cross libc6-dev-arm64-cross libc6-dev-s390x-cross libc6-dev-loong64-cross
8887
- name: Set OPT_CLFAGS
8988
run: |
90-
echo OPT_CFLAGS="${{ matrix.optimization }}" >> $GITHUB_ENV
91-
# TODO: Sanitizer fails in armhf and aarch64
92-
# echo OPT_CFLAGS="${{ matrix.optimization }} ${{ matrix.sanitize }}" >> $GITHUB_ENV
89+
echo OPT_CFLAGS="${{ matrix.optimization }} ${{ matrix.sanitize }}" >> $GITHUB_ENV
9390
- name: arm-linux-gnueabi
9491
env:
9592
OPT_CFLAGS: "-latomic"
@@ -102,8 +99,6 @@ jobs:
10299
run: |
103100
make relro_pie_tests TARGET_PLATFORM=arm-linux-gnueabihf
104101
- name: aarch64-linux-gnu
105-
# TODO: aarch64 fails with optimizations https://github.com/kubo/plthook/issues/51
106-
if: ${{ matrix.optimization == '' }}
107102
run: |
108103
make relro_pie_tests TARGET_PLATFORM=aarch64-linux-gnu
109104
- name: powerpc-linux-gnu
@@ -118,6 +113,9 @@ jobs:
118113
- name: s390x-linux-gnu
119114
run: |
120115
make relro_pie_tests TARGET_PLATFORM=s390x-linux-gnu QEMU_ARCH=s390x
116+
- name: loongarch64-linux-gnu
117+
run: |
118+
make relro_pie_tests TARGET_PLATFORM=loongarch64-linux-gnu QEMU_ARCH=loongarch64 GCC_VERSION=14
121119
122120
tests_on_macos:
123121
name: Tests on macOS

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,23 @@ RUN apt update \
1515
gcc-riscv64-linux-gnu \
1616
gcc-s390x-linux-gnu \
1717
gcc-sparc64-linux-gnu \
18+
gcc-14-loongarch64-linux-gnu \
1819
libc6-dev-armhf-cross \
1920
libc6-dev-ppc64el-cross \
2021
libc6-dev-powerpc-cross \
2122
libc6-dev-armel-cross \
2223
libc6-dev-arm64-cross \
2324
libc6-dev-s390x-cross \
24-
libc6-dev-sparc64-cross
25+
libc6-dev-sparc64-cross \
26+
libc6-dev-loong64-cross
2527

2628
WORKDIR /plthook
2729

2830
COPY . .
2931

3032
WORKDIR /plthook/test
3133

32-
ENV OPT_CFLAGS="-O1"
34+
ENV OPT_CFLAGS="-O2"
3335

3436
RUN echo "Running tests" \
3537
&& make relro_pie_tests TARGET_PLATFORM=aarch64-linux-gnu \
@@ -39,7 +41,8 @@ RUN echo "Running tests" \
3941
&& make relro_pie_tests TARGET_PLATFORM=powerpc-linux-gnu QEMU_ARCH=ppc \
4042
&& make relro_pie_tests TARGET_PLATFORM=powerpc64le-linux-gnu QEMU_ARCH=ppc64le \
4143
&& make relro_pie_tests TARGET_PLATFORM=riscv64-linux-gnu QEMU_ARCH=riscv64 \
42-
&& make relro_pie_tests TARGET_PLATFORM=s390x-linux-gnu QEMU_ARCH=s390x
44+
&& make relro_pie_tests TARGET_PLATFORM=s390x-linux-gnu QEMU_ARCH=s390x \
45+
&& make relro_pie_tests TARGET_PLATFORM=loongarch64-linux-gnu QEMU_ARCH=loongarch64 GCC_VERSION=14
4346

4447
# TODO:
4548
# \

plthook_elf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@
113113
#elif defined __s390x__
114114
#define R_JUMP_SLOT R_390_JMP_SLOT
115115
#define R_GLOBAL_DATA R_390_GLOB_DAT
116+
#elif defined __loongarch64
117+
#define R_JUMP_SLOT R_LARCH_JUMP_SLOT
118+
#define R_GLOBAL_DATA R_LARCH_64
116119
#elif 0 /* disabled because not tested */ && (defined __sparc || defined __sparc__)
117120
#define R_JUMP_SLOT R_SPARC_JMP_SLOT
118121
#define R_GLOBAL_DATA R_SPARC_GLOB_DAT

test/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ifeq ($(UNAME_S),Linux)
2323
# Linux
2424
TESTS = relro_pie_tests
2525
ifneq ($(TARGET_PLATFORM),)
26-
CC = $(TARGET_PLATFORM)-gcc
26+
CC = $(TARGET_PLATFORM)-gcc$(if $(GCC_VERSION),-$(GCC_VERSION))
2727
KICK_CMD = qemu-$(or $(QEMU_ARCH),$(shell echo $(TARGET_PLATFORM) | sed -e 's/-.*//')) -L /usr/$(TARGET_PLATFORM)
2828
endif
2929
endif
@@ -65,8 +65,8 @@ all: libtest.$(SOEXT) testprog$(EXEEXT)
6565
libtest.$(SOEXT): libtest.c libtest.h
6666
$(CC) $(CFLAGS_SHARED) $(CFLAGS) -DLIBTEST_DLL -o libtest.$(SOEXT) libtest.c -lm $(LDFLAGS)
6767

68-
testprog$(EXEEXT): testprog.c ../$(PLTHOOK_C) libtest.h
69-
$(CC) $(CFLAGS_EXE) $(CFLAGS) -o testprog$(EXEEXT) -I.. testprog.c ../$(PLTHOOK_C) -L. -ltest $(LIBS) $(LDFLAGS)
68+
testprog$(EXEEXT): testprog.c testlazybinding.c ../$(PLTHOOK_C) libtest.h
69+
$(CC) $(CFLAGS_EXE) $(CFLAGS) -o testprog$(EXEEXT) -I.. testprog.c testlazybinding.c ../$(PLTHOOK_C) -L. -ltest $(LIBS) $(LDFLAGS)
7070

7171
run_tests: clean libtest.$(SOEXT) testprog$(EXEEXT)
7272
LD_LIBRARY_PATH=. $(KICK_CMD) ./testprog$(EXEEXT) open

test/Makefile.win32

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ all: libtest.dll testprog.exe
66
libtest.dll: libtest.c libtest.h
77
cl /nologo $(DLL_CFLAGS) /DLIBTEST_DLL /Felibtest.dll libtest.c /link /def:libtest.def
88

9-
testprog.exe: testprog.c ../plthook_win32.c libtest.h
10-
cl /nologo $(EXE_CFLAGS) /Fetestprog -I.. testprog.c ..\plthook_win32.c libtest.lib
9+
testprog.exe: testprog.c testlazybinding.c ../plthook_win32.c libtest.h
10+
cl /nologo $(EXE_CFLAGS) /Fetestprog -I.. testprog.c testlazybinding.c ..\plthook_win32.c libtest.lib
1111

1212
check: libtest.dll testprog.exe
1313
.\testprog.exe open

test/android/jni/Android.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ include $(BUILD_SHARED_LIBRARY)
1212
include $(CLEAR_VARS)
1313

1414
LOCAL_MODULE := testprog
15-
LOCAL_SRC_FILES := ../../testprog.c ../../../plthook_elf.c
15+
LOCAL_SRC_FILES := ../../testprog.c ../../testlazybinding.c ../../../plthook_elf.c
1616
LOCAL_C_INCLUDES := ../.. ../../..
1717
LOCAL_SHARED_LIBRARIES := libtest
1818

test/libtest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define LIBTESTAPI __declspec(dllimport)
99
#endif
1010
#else
11-
#define LIBTESTAPI
11+
#define LIBTESTAPI __attribute__((visibility("default")))
1212
#endif
1313

1414
LIBTESTAPI

test/testlazybinding.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stddef.h>
2+
#include "libtest.h"
3+
4+
/*
5+
https://github.com/metacall/plthook/issues/4
6+
https://github.com/kubo/plthook/pull/55#issuecomment-2863552101
7+
*/
8+
double strtod_lazy_binding(void)
9+
{
10+
double num = strtod_cdecl("3.7", NULL);
11+
return num;
12+
}

test/testprog.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ enum open_mode {
3232
OPEN_MODE_BY_ADDRESS,
3333
};
3434

35+
/*
36+
https://github.com/metacall/plthook/issues/4
37+
https://github.com/kubo/plthook/pull/55#issuecomment-2863552101
38+
*/
39+
double strtod_lazy_binding(void);
40+
3541
static enum_test_data_t funcs_called_by_libtest[] = {
3642
#if defined __APPLE__ && defined __LP64__
3743
{"_strtod", 0},
@@ -335,7 +341,8 @@ int main(int argc, char **argv)
335341
}
336342

337343
/* Resolve the function addresses by lazy binding. */
338-
strtod_cdecl("3.7", NULL);
344+
// strtod_cdecl("3.7", NULL);
345+
strtod_lazy_binding();
339346
#if defined _WIN32 || defined __CYGWIN__
340347
strtod_stdcall("3.7", NULL);
341348
strtod_fastcall("3.7", NULL);

0 commit comments

Comments
 (0)