From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1983) id C02953858D37; Thu, 21 Apr 2022 20:09:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C02953858D37 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Carl Love To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix for gdb.base/solib-search.exp test. X-Act-Checkin: binutils-gdb X-Git-Author: Carl Love X-Git-Refname: refs/heads/master X-Git-Oldrev: b0b299477cc7e538b2387ec05b92c7261bf31052 X-Git-Newrev: 83ac2319e75a6313e17265d18820487e80dd9619 Message-Id: <20220421200932.C02953858D37@sourceware.org> Date: Thu, 21 Apr 2022 20:09:32 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2022 20:09:32 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D83ac2319e75a= 6313e17265d18820487e80dd9619 commit 83ac2319e75a6313e17265d18820487e80dd9619 Author: Carl Love Date: Tue Mar 22 15:23:44 2022 -0500 Fix for gdb.base/solib-search.exp test. =20 The variable right_lib_flags is not being set correctly to define RIGHT. The value RIGHT is needed to force the address of the library functions lib1_func3 and lib2_func4 to occur at different address in the wrong and right libraries. =20 With RIGHT defined correctly, functions lib1_func3 and lib2_func4 occur at different addresses the test runs correctly on Powerpc. =20 The test needs the lib2 addresses to be different in the right and wrong cases. That is the point of introducing function lib2_spacer with the ifdef RIGHT compiler directive. =20 On Intel, the ARRAY_SIZE of 1 versus 8192 is sufficient to get the dynamic linker to move the addresses of the library. You can also get the same effect on PowerPC but you must use a value much larger than 8192. =20 The key thing is that the test was not properly setting RIGHT to defined to get the lib2_spacer function on Intel and Powerpc. =20 Without the patch, we have the Intel backtrace for the bad libraries: =20 backtrace #0 break_here () at /home/ ... /gdb/testsuite/gdb.base/solib-search.c:= 30 #1 0x00007ffff7fae156 in ?? () #2 0x00007fffffffc150 in ?? () #3 0x00007ffff7fbb156 in ?? () #4 0x00007fffffffc160 in ?? () #5 0x00007ffff7fae146 in ?? () #6 0x00007fffffffc170 in ?? () #7 0x00007ffff7fbb146 in ?? () #8 0x00007fffffffc180 in ?? () #9 0x0000555555555156 in main () at /home/ ... /binutils-gdb/gdb/tests= uite/gdb.base/solib-search.c:23 Backtrace stopped: previous frame inner to this frame (corrupt stack?) (gdb) PASS: gdb.base/solib-search.exp: backtrace (with wrong libs) (dat= a collection) =20 The backtrace on Intel with the good libraries is: =20 backtrace #0 break_here () at /.../binutils-gdb/gdb/testsuite/gdb.base/solib-sea= rch.c:30 #1 0x00007ffff7fae156 in lib2_func4 () at /.../binutils-gdb/gdb/testsu= ite/gdb.base/solib-search-lib2.c:49 #2 0x00007ffff7fbb156 in lib1_func3 () at /.../gdb.base/solib-search-l= ib1.c:49 #3 0x00007ffff7fae146 in lib2_func2 () at /.../testsuite/gdb.base/soli= b-search-lib2.c:30 #4 0x00007ffff7fbb146 in lib1_func1 () at /.../gdb.base/solib-search-l= ib1.c:30 #5 0x0000555555555156 in main () at /...solib-search.c:23 (gdb) PASS: gdb.base/solib-search.exp: backtrace (with right libs) (dat= a collection) PASS: gdb.base/solib-search.exp: backtrace (with right libs) =20 In one case the backtrace is correct and the other it is wrong on Intel. This is due to the fact that the ARRAY_SIZE caused the dynamic linker to move the library function addresses around. I believe it has to do with the default size of the data and code sections used by the dynamic linker. =20 So without the patch the backtrace on PowerPC looks like: =20 backtrace #0 break_here () at /.../solib-search.c:30 #1 0x00007ffff7f007f4 in lib2_func4 () at /.../solib-search-lib2.c:49 #2 0x00007ffff7f307f4 in lib1_func3 () at /.../solib-search-lib1.c:49 #3 0x00007ffff7f007ac in lib2_func2 () at /.../solib-search-lib2.c:30 #4 0x00007ffff7f307ac in lib1_func1 () at /.../solib-search-lib1.c:30 #5 0x000000001000074c in main () at /.../solib-search.c:23 =20 for both the good and bad libraries. =20 The patch fixes defining RIGHT in solib-search-lib1.c and solib-search- lib2.c. Note, without the patch the lib1_spacer and lib2_spacer functions do not show up in the object dump of the Intel or Powerpc libraries as it should. The patch fixes that by making sure RIGHT gets defined. =20 Now with the patch the backtrace for the bad library on PowerPC looks like: =20 backtrace #0 break_here () at /.../solib-search.c:30 #1 0x00007ffff7f0083c in __glink_PLTresolve () from /.../solib-search-= lib2.so Backtrace stopped: frame did not save the PC =20 And the backtrace for the good libraries on PowerPC looks like: =20 backtrace #0 break_here () at /.../solib-search.c:30 #1 0x00007ffff7f0083c in lib2_func4 () at /.../solib-search-lib2.c:49 #2 0x00007ffff7f3083c in lib1_func3 () at /.../solib-search-lib1.c:49 #3 0x00007ffff7f007cc in lib2_func2 () at /.../solib-search-lib2.c:30 #4 0x00007ffff7f307cc in lib1_func1 () at /.../solib-search-lib1.c:30 #5 0x000000001000074c in main () at /.../solib-search.c:23 (gdb) PASS: gdb.base/solib-search.exp: backtrace (with right libs) (dat= a collection) PASS: gdb.base/solib-search.exp: backtrace (with right libs) =20 The issue then is on Power where the ARRAY_SIZE of 1 versus 8192 is not sufficient to cause the dymanic linker to allocate the libraries at different addresses. I don't claim to understand the specifics of how the dynamic linker works and what the default size is for the data and code sections are. My guess is by default PowerPC allocates a larger data size by default, which is large enough to hold array[8192]. The default size of the data section allocated by the dynamic linker on Intel is not large enough to hold array[8192] thus causing the code section on Intel to have to move when the large array is defined. =20 Note on PowerPC, if you make ARRAY_SIZE big enough, then you will cause the library addresses to occur at different addresses as the larger data section forces the code section to a different address. That was actually my original fix for the program until I spoke with Doug Evans who originally wrote the test. Doug noticed that RIGHT was not getting defined as he originally intended in the test. =20 With the patch to fix the definition of RIGHT, PowerPC has a bad and a good backtrace because the address of lib1_func3 and lib2_func4 both move because lib1_spacer and lib2_spacer are now defined before lib1_func3 and lib2_func4. =20 Without the patch, the lib1_spacer and lib2_spacer function doesn't show up in the binary for the correct or incorrect library on Intel or Power= PC. With the patch, RIGHT gets defined as originally intended for the test = on both architectures and lib1_spacer and lib2_spacer function show up in = the binaries on both architectures changing the other function addresses as intended thus causing the test work as intended on PowerPC. Diff: --- gdb/testsuite/gdb.base/solib-search.exp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.base/solib-search.exp b/gdb/testsuite/gdb.ba= se/solib-search.exp index eaabe508bf0..202e79d85de 100644 --- a/gdb/testsuite/gdb.base/solib-search.exp +++ b/gdb/testsuite/gdb.base/solib-search.exp @@ -54,7 +54,7 @@ set binfile2_lib [standard_output_file ${libname2}.so] =20 set lib_flags [list debug ldflags=3D-Wl,-Bsymbolic] set wrong_lib_flags "$lib_flags additional_flags=3D-DARRAY_SIZE=3D1" -set right_lib_flags "$lib_flags additional_flags=3D-DARRAY_SIZE=3D8192 -DR= IGHT" +set right_lib_flags "$lib_flags additional_flags=3D-DARRAY_SIZE=3D8192 add= itional_flags=3D-DRIGHT" =20 # Binary file. standard_testfile .c