From b21a7e3f59c8b3b10b184ccabde6a39dacf23b57 Mon Sep 17 00:00:00 2001 From: Zhou Kang Date: Tue, 18 Jul 2023 01:07:10 +0000 Subject: [PATCH] fix test thread var --- src/elf_relocation.c | 1 - tests/meson.build | 4 ++-- tests/test_app/Makefile | 15 ++++++++++----- tests/test_app/meson.build | 3 ++- tests/test_simple/Makefile | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/elf_relocation.c b/src/elf_relocation.c index 9393a69..9f7b2e4 100644 --- a/src/elf_relocation.c +++ b/src/elf_relocation.c @@ -244,7 +244,6 @@ void modify_rela_dyn_item(elf_link_t *elf_link, elf_file_t *src_ef, Elf64_Rela * case R_X86_64_TPOFF32: // Offset in initial TLS block // 00000000001f0d78 0000000000000012 R_X86_64_TPOFF64 38 - // [36] .data PROGBITS 00000000001f1000 1f0000 0016a8 00 WA 0 0 32 dst_rela->r_addend = elf_get_new_tls_offset(elf_link, src_ef, src_rela->r_addend); break; case R_X86_64_COPY: diff --git a/tests/meson.build b/tests/meson.build index 73177ca..3f6d3a0 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -7,7 +7,7 @@ foreach test:tests sources = [] includes = [] cflags = [] - ldflags = ['-Wl,--emit-relocs', '-Wl,-z,relro,-z,now'] + ldflags = ['-Wl,--emit-relocs', '-Wl,-z,relro,-z,now', '-pie'] subdir(name) -endforeach \ No newline at end of file +endforeach diff --git a/tests/test_app/Makefile b/tests/test_app/Makefile index 50dac74..616c3df 100644 --- a/tests/test_app/Makefile +++ b/tests/test_app/Makefile @@ -12,6 +12,8 @@ LIBHOOK_R=/usr/lib/relocation/libhook.so.relocation LIBC=/usr/lib64/libc.so.6 LIBC_R=/usr/lib/relocation$(LIBC).relocation +MODE?=--static-nold +#MODE=--static-nolibc .PHONY: all @@ -51,22 +53,25 @@ run1: test-s: prepare clear @echo ===rto=== - $(SYSBOOST) --static $(TEST_APP) $(LIB1) $(LIB2) $(LIBC) + $(SYSBOOST) $(MODE) $(TEST_APP) $(LIB1) $(LIB2) $(LIBC) readelf -W -a $(TEST_APP).rto > test_app.rto.elf objdump -d $(TEST_APP).rto > test_app.rto.asm - @echo ===run-ori=== + @echo ===old=== $(TEST_APP) @echo ===run=== - ./test_app.rto + $(TEST_APP).rto rto: - gdb --args $(SYSBOOST) --static $(TEST_APP) $(LIB1) $(LIB2) $(LIBC) + gdb --args $(SYSBOOST) $(MODE) $(TEST_APP) $(LIB1) $(LIB2) $(LIBC) run: - gdb --args ./test_app.rto + gdb --args $(TEST_APP).rto env: echo 0 > /proc/sys/kernel/randomize_va_space cat /proc/sys/kernel/randomize_va_space readelf -W -a $(LIBC) > libc.so.elf objdump -d $(LIBC) > libc.so.asm + +clean: + $(RM) *.o *.ro *.old *.so *.asm *.elf *.rto *.out test_app diff --git a/tests/test_app/meson.build b/tests/test_app/meson.build index 98f05cb..67f90c4 100644 --- a/tests/test_app/meson.build +++ b/tests/test_app/meson.build @@ -4,6 +4,7 @@ sources = files(['common_func.c', cflags += ['-fpic', '-pthread', '-ldl'] ldflags += ['-pie', '-ldl'] +lk_args += ['-Wl,--emit-relocs', '-Wl,-z,relro,-z,now'] # Add a target for libutil2.so shared library util1 = shared_library('util1', 'util1.c', @@ -31,4 +32,4 @@ executable('test_app', sources, link_args: ldflags, build_rpath : './', dependencies: test_app_dep, - include_directories: includes) \ No newline at end of file + include_directories: includes) diff --git a/tests/test_simple/Makefile b/tests/test_simple/Makefile index c6e2de0..14648e3 100644 --- a/tests/test_simple/Makefile +++ b/tests/test_simple/Makefile @@ -60,8 +60,8 @@ env: cat /proc/sys/kernel/randomize_va_space readelf -W -a $(LIBC_R) > libc.so.elf objdump -d $(LIBC_R) > libc.so.asm - readelf -W -a $(LIBLD_R) > ld.so.elf - objdump -d $(LIBLD_R) > ld.so.asm + readelf -W -a $(LIBLD) > ld.so.elf + objdump -d $(LIBLD) > ld.so.asm clean: $(RM) *.o *.ro *.old *.so *.asm *.elf *.rto *.out simple_app -- Gitee