[EXT] Re: help! why a 'so' can't load its dependent 'so' to the pre-defined address
Kewen.Lin
linkw@linux.ibm.com
Tue Dec 17 02:42:00 GMT 2019
on 2019/12/16 脧脗脦莽4:13, Xing-Hao Chen wrote:
> Hi Kewen,
> Appreciate very much for your reply,
>
> "I found that if you force the virtual address for the libtestScript.so generation as well, you can see the expected result you wanted."
>
> But how to force the VA for libtestScript.so?
> I tried "-Wl,-Ttext=0xXXXX", but will suffer some link problems.
> How can I assign the 0xXXXX, while fixing the load VA of libcpss.so/libhelper.so(to be 0x10000000 / 0x14600000) which libtestScript.so relies on?
>
Hi,
I think you can still use linker script scheme for libtestScript.so generation like what you have for libcpss.so/libhelper.so. I used linker script for libt1.so libt3.so generation and see the ldd dump as below. Here libt3 is like libtestScript.so, libt1 is like libcpss.so/libhelper.so and libt2 is as normal.
$ LD_LIBRARY_PATH=. ldd ./libt3.so
linux-vdso64.so.1 => (0x00003fffadb40000)
libt1.so => ./libt1.so (0x0000020000000000)
libt2.so => ./libt2.so (0x00003fffadb10000)
libc.so.6 => /lib/powerpc64le-linux-gnu/libc.so.6 (0x00003fffad910000)
/lib64/ld64.so.2 (0x00003fffadb60000)
** simple ld scripts **
ld01.txt:
SECTIONS
{
. = 0x20000000000;
.text : { *(.text) }
}
ld03.txt:
SECTIONS
{
. = 0x40000000000;
.text : { *(.text) }
}
PS: above scripts are really simple, just for proof of concepts.
** commands **
gcc -shared -fPIC t1.c -o libt1.so -Tld01.txt
gcc -shared -fPIC t2.c -o libt2.so
gcc -shared -fPIC t3.c -o libt3.so -Tld03.txt -L. -lt1 -lt2 -Wl,-R.
gcc main.c -L. -lt3
Note that you need to avoid that the module libtestScript.so conflicts with libcpss.so/libhelper.so, for example using ld01.txt for libt3.so generation, it gets the dumping as below.
$ LD_LIBRARY_PATH=. ldd ./libt3.so
linux-vdso64.so.1 => (0x00003fffb0550000)
libt1.so => ./libt1.so (0x00003fffa0540000)
libt2.so => ./libt2.so (0x00003fffa0510000)
libc.so.6 => /lib/powerpc64le-linux-gnu/libc.so.6 (0x00003fffa0310000)
/lib64/ld64.so.2 (0x00003fffb0570000)
** simple src **
t1.c:
int t1(int a, int b) { return a + b; }
t2.c:
int t2(int a, int b) { return a - b; }
t3.c:
extern int t1(int a, int b);
extern int t2(int a, int b);
int t3(int a, int b){
return t1(a, b) + t2(b, a);
}
main.c:
extern int t3(int a, int b);
int main() {
int a = 1;
int b = 2;
int c = t3(a+b, b-a);
return c;
}
I tested it on powerpc64le-linux-gnu, with gcc 5.4.0 and GNU ld 2.26.1, FYI in case it matters.
BR,
Kewen
> In summary of my requirement -
> When loading libtestScript.so, the loader should load its dependent two so(libcpss.so/libhelper.so) into the pre-defined VA(to be 0x10000000 / 0x14600000)
>
> How can I do? Any suggestion is appreciated.
>
More information about the Gcc-help
mailing list