Bug 561080 - the value of a global variable in shared library always displays the initialized value
Summary: the value of a global variable in shared library always displays the initiali...
Status: RESOLVED FIXED
Alias: None
Product: TCF
Classification: Tools
Component: Agent (show other bugs)
Version: unspecified   Edit
Hardware: Power PC All
: P3 normal (vote)
Target Milestone: 1.7   Edit
Assignee: Project Inbox CLA
QA Contact: Eugene Tarassov CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-12 22:46 EDT by wenyan xin CLA
Modified: 2021-06-25 16:23 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wenyan xin CLA 2020-03-12 22:46:24 EDT
defines and exports a global variable in one shared library.

then a executive accesses this global variable that exported by the previous shared library.

when we debug the executive file through TCF, the global variable will be displayed correctly if in function that defines in executive itself;

But the value of the global variable always displays the initialized value if in function that defines in shared library itself.

for examples:

---------------------------
sharedlib.c, this is the shared library source file:

int slvar = 10;

void fun_sl()
{
    // ERROR: here the value of slvar variable is 10, it should be 100;
    slvar = 200; 
}

---------------------------

executive.c, this is a sample executive file

extern int slvar;
extern void fun_sl();

int main()
{
    slvar = 100;
    fun_sl(); 

    // ERROR: here the value of slvar variable is 100, it should be 200;
    return 0;
}
Comment 1 wenyan xin CLA 2020-03-12 22:53:54 EDT
this issue only happens on ppc 32, and compilers/gnu-8.3.0.1/x86_64-linux2/bin/ccppcspe
Comment 2 wenyan xin CLA 2020-03-12 23:05:23 EDT
the global variable that exported in a shared library will be allocated space both in .bss section in executive file and .data section in shared library.

when the executive starts up, the initialized value will be copied to .bss section in executive file from the .data section in shared library.

then all of access to the global variable should referenced to .bss section in executive. 

I think this issue happened is because the TCF reference the global variable to the .data section when debug into the function that defined in shared library.

thanks
Wenyan
Comment 3 wenyan xin CLA 2020-03-13 03:58:58 EDT
BTW:

when we are debugging the executive, we can see that the address of the global variable is in shared library address range in debugger.
Comment 4 Eugene Tarassov CLA 2020-03-19 12:24:44 EDT
This is caused by "copy relocations" - relatively obscure under-documented aspect of shared libraries implementation. GCC debug info for copy relocations is just plain wrong - the info should point to GOT instead of .data section. So, technically, it is a compiler bug.

I have committed a workaround.

Fixed.
Thanks!