This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Regression for gdb.fortran/library-module.exp [Re: [RFA] choose symbol from given block's objfile first.]


On Mon, 14 May 2012 18:56:37 +0200, Joel Brobecker wrote:
> So this is another example of copy-relocation?

No, this was just overriding library's symbol by executable's symbol.

$ main executable's has now just 'extern int x;'
echo -e '#include <stdio.h>\nint x=1;void f(void){printf("lib:%d\\n",x);}'|gcc -x c -fPIC -Wall -shared -o var.so -;echo -e '#include <stdio.h>\nextern int x;extern void f(void);int main(void){printf("main:%d\\n",x);f();return 0;}'|gcc ./var.so -x c -Wall -o var -;./var
main:1
lib:1
$ readelf -Wr var
    Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
0000000000600a40  0000000700000005 R_X86_64_COPY          0000000000600a40 x + 0

This is copy-relocation because the variable must be in the main executable
but at the same time it must be initialized from the library's value.


> When you say this is perfectly defined, this looks horrifying to me. It
> feels like you can break a shared library's code that way...

If library does not want to get its data overriden it should use
-fvisibility=hidden and properly mark any really exported variables by
"__attribute__ ((visibility("default")))".  See man gcc for -fvisibility.

Exporting any variables from shared libraries should be rather avoided anyway
as it is generally expensive, because compiler has to ensure &variable has the
same address from any module.

That -fvisibility=hidden is not default is just unfortunately backward
compatibility.  The default -fvisibility=default is needlessly expensive.
glibc does these tricks with visibilities.


Regards,
Jan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]