Bug 234068

Summary: prelinking a c++ shared library causes the symbols to not load correctly in gdb
Product: Red Hat Enterprise Linux 4 Reporter: Cameron Ring <cam>
Component: prelinkAssignee: Jakub Jelinek <jakub>
Status: CLOSED WONTFIX QA Contact:
Severity: low Docs Contact:
Priority: medium    
Version: 4.4CC: aoliva
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 16:01:13 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Repro case
none
Patch none

Description Cameron Ring 2007-03-26 20:50:47 UTC
Description of problem: prelinking a c++ shared library causes the symbols to
not load correctly in gdb.

Version-Release number of selected component (if applicable): 0.3.9-2

How reproducible: 100% with the provided test case

Steps to Reproduce:
1. Uncompress provided test case and cd into that directory
2. make
3. /usr/sbin/prelink -r0x22b000 libtest.so (the bug happens whether you prelink
or even just relocate. relocating has the benefit of not requiring root)
4. LD_LIBRARY_PATH=. gdb exe
5. b main
6. r
7. s
8. s
  
Actual results:
C (this=Could not find the frame base for "C".
) at lib.cc:11
11      C::C(bool f) {

Expected results:
C (this=0xbfecb457, f=true) at lib.cc:11
11      C::C(bool f) {

Additional info:
As stated in http://people.redhat.com/jakub/prelink.pdf, relocating a library
with prelink should be equivalent to specifying a non-standard base address
using a linker script. However, readelf -wo shows a discrepancy in the
.debug_loc section for a  library relocated by prelink and one built using a
linker script (ignore the readelf bug that only prints the first group, that's
enough to see the problem):

Relocated by prelink:
Contents of the .debug_loc section:
    Offset   Begin    End      Expression
    00000000 00000640 00000641 (DW_OP_breg4: 4)
    00000000 00000641 00000643 (DW_OP_breg4: 8)
    00000000 00000643 00000647 (DW_OP_breg5: 8)


Linker script:
Contents of the .debug_loc section:
    Offset   Begin    End      Expression
    00000000 0022b640 0022b641 (DW_OP_breg4: 4)
    00000000 0022b641 0022b643 (DW_OP_breg4: 8)
    00000000 0022b643 0022b647 (DW_OP_breg5: 8)

The above shows that prelink is not updating the .debug_loc section when
relocating the library, causing gdb to not be able to find the symbols. 

The included patch makes sure to update the .debug_loc section, which allows gdb
to find the symbols correctly.

Also, stripping the symbols into a separate symbol file works around the problem
as gdb is then responsible for offsetting the symbols by the library base address.

Comment 1 Cameron Ring 2007-03-26 20:50:47 UTC
Created attachment 150954 [details]
Repro case

Comment 2 Cameron Ring 2007-03-26 20:52:06 UTC
Created attachment 150955 [details]
Patch

Fix for the bug by making sure .debug_loc is updated in adjust_dwarf2_loc

Comment 3 Jiri Pallich 2012-06-20 16:01:13 UTC
Thank you for submitting this issue for consideration in Red Hat Enterprise Linux. The release for which you requested us to review is now End of Life. 
Please See https://access.redhat.com/support/policy/updates/errata/

If you would like Red Hat to re-consider your feature request for an active release, please re-open the request via appropriate support channels and provide additional supporting details about the importance of this issue.