Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename-dynamic-symbols.sh fails during the compilation with "span access out of range" error #503

Open
Duraisankarp opened this issue Jun 19, 2023 · 4 comments
Labels

Comments

@Duraisankarp
Copy link

I am compiling the patchelf 0.18.0 for s390x and getting these failure,

Compilation failure:

[ 70s] FAIL: rename-dynamic-symbols.sh
[ 70s] ===============================
[ 70s]
[ 70s] patching ELF file '/home/abuild/rpmbuild/BUILD/patchelf-0.18.0/tests/libmany-syms.so'
[ 70s] skip renaming dynamic symbol nskip renaming dynamic symbol nrenaming dynamic symbol __cxa_finalize to __cxa_finalize_special_suffix
[ 70s] renaming dynamic symbol _ITM_deregisterTMCloneTable to _ITM_deregisterTMCloneTable_special_suffix
[ 70s] renaming dynamic symbol gmon_start to __gmon_start___special_suffix
[ 70s] renaming dynamic symbol _ITM_registerTMCloneTable to _ITM_registerTMCloneTable_special_suffix
..
..
..
[ 70s] patchelf: error: Span access out of range.
[ 70s] FAIL rename-dynamic-symbols.sh (exit status: 1)

I suspect the test script for injecting out of range size.
Can you have a look at it ?

@Prime541
Copy link

Hello, I have the same issue with Linux x86_64 since patchelf-0.18.0.
FAIL: rename-dynamic-symbols.sh

File: tests/rename-dynamic-symbols.sh.log

patching ELF file '/tmp/tmp.NO1jJ1rhHs/patchelf-0.18.0/tests/libmany-syms.so'
skip renaming dynamic symbol nrenaming dynamic symbol _ITM_deregisterTMCloneTable to _ITM_deregisterTMCloneTable_special_suffix
renaming dynamic symbol __gmon_start__ to __gmon_start___special_suffix
[...]
./many-syms-main: Symbol `f1999_special_suffix' causes overflow in R_X86_64_PC32 relocation
./many-syms-main: Symbol `f2000_special_suffix' causes overflow in R_X86_64_PC32 relocation
./rename-dynamic-symbols.sh: line 84: 85582 Segmentation fault      (core dumped) env LD_BIND_NOW=1 LD_LIBRARY_PATH="${PWD}" ./many-syms-main
FAIL rename-dynamic-symbols.sh (exit status: 139)
/tmp/tmp.NO1jJ1rhHs/patchelf-0.18.0>(cd ./tests/scratch/rename-dynamic-symbols/env && gdb ./many-syms-main ./core.87468)
[...]
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00005568456cb130 in ?? ()
(gdb) bt
#0  0x00005568456cb130 in ?? ()
#1  0x00005567d0e59e8b in main () at many-syms-main.c:2
uname -a
Linux HOSTNAME 4.12.14-122.162-default #1 SMP Tue Jun 6 12:25:40 UTC 2023 (02a1ae5) x86_64 x86_64 x86_64 GNU/Linux

Cause:
0.17.2...0.18.0
0b6b666
#459

@Duraisankarp
Copy link
Author

Duraisankarp commented Jul 3, 2023

@brenoguim Can you have a look at this issue and help ?

@jamborm
Copy link

jamborm commented Mar 7, 2024

I see the same issue when running make check on SUSE Linux Enterprise 15 system (as opposed to openSUSE Tumbleweed). I have not really investigated the details, but what seems wrong is that many_syms_main-many-syms-main.o is compiled with -pie but without -fPIE. Fixing that issue also made the make check failure go away. Can you try if the following patch helps?

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8bbded7..49454d4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -164,7 +164,7 @@ many_syms_main_SOURCES = many-syms-main.c
 many_syms_main_LDFLAGS = $(LDFLAGS_local) 
 many_syms_main_LDADD = -lmany-syms $(AM_LDADD)
 many_syms_main_DEPENDENCIES = libmany-syms.so
-many_syms_main_CFLAGS = -pie
+many_syms_main_CFLAGS = -pie -fPIE
 libmany_syms_so_SOURCES = many-syms.c
 libmany_syms_so_LDFLAGS = $(LDFLAGS_sharedlib)
 

jamborm added a commit to jamborm/patchelf that referenced this issue Mar 8, 2024
when building and then checking patchelf on openSUSE Leap 15.5, the
rename-dynamic-symbols.sh test fails.  The test builds a test library
and executable called many-syms-main, then runs patchelf to rename
symbols and then checks that many-syms-main still runs successfully.

On Leap the run fails with many messages like

  ./many-syms-main: Symbol `f1947' causes overflow in R_X86_64_PC32 relocation

and then terminates with a Segmentation fault.  The interesting bit is
that it however fails so even before patchelf touches it.

The binary is built and linked with option -pie which produces an
executable which is supposedly position independent but does not
actually contain code position independent code which requires
compiler option -fPIE (of -fpie or -fPIC or -fpic).  As a result the
calls in the generated assembly do not go through the PLT.

This patch merely adresses that by adding the -fPIE option to the
CFLAGS for the test.
@jamborm
Copy link

jamborm commented Mar 8, 2024

I have created a pull request #547 with this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants