mailing list of musl libc
 help / color / mirror / Atom feed
* [musl] [QUESTION] how to gdb dynamic linker for musl?
@ 2020-12-07 13:37 Chen Wang
  2020-12-07 16:46 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Chen Wang @ 2020-12-07 13:37 UTC (permalink / raw)
  To: musl; +Cc: unicorn_wang

[-- Attachment #1: Type: text/plain, Size: 1692 bytes --]

Hello,
I confugure and make musl with following:

CFLAGS=-g CROSS_COMPILE=riscv64-unknown-linux-gnu- ./configure --prefix=/home/u/ws/musl/install --exec-prefix=/home/u/ws/musl/install --syslibdir=/home/u/ws/musl/install

create the executable with: ./install/bin/musl-gcc -g test.c

Then I tried to debug:
$ qemu-riscv64 -g 1234 ./a.out
then launch gdb:
$ riscv64-unknown-linux-gnu-gdb a.out

but after I tried to target remote, gdb oops and tell me:
```
gdb) target remote:1234
Remote debugging using :1234
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0x0000004000850ae2 in ?? ()
```

I tried to set sysroot but does NOT take effect:
```
(gdb) set sysroot /home/u/ws/musl/install/
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
(gdb) set sysroot /home/u/ws/musl/install/lib
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
```
I checked the a.out
```
$ riscv64-unknown-linux-gnu-readelf -l a.out
......
  INTERP         0x00000000000001c8 0x00000000000101c8 0x00000000000101c8
                 0x000000000000002d 0x000000000000002d  R      0x1
      [Requesting program interpreter: /home/u/ws/musl/install/ld-musl-riscv64.so.1]
......
```
And I can run with qemu directly: $ qemu-riscv64 ./a.out, this works, but why I can not debug with gdb? Who can help me out? Thanks in adv.




Best Regards

Wang Chen

[-- Attachment #2: Type: text/html, Size: 2828 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [musl] [QUESTION] how to gdb dynamic linker for musl?
  2020-12-07 13:37 [musl] [QUESTION] how to gdb dynamic linker for musl? Chen Wang
@ 2020-12-07 16:46 ` Rich Felker
  2020-12-08  0:55   ` Chen Wang
  2020-12-08  2:34   ` Chen Wang
  0 siblings, 2 replies; 4+ messages in thread
From: Rich Felker @ 2020-12-07 16:46 UTC (permalink / raw)
  To: Chen Wang; +Cc: musl

On Mon, Dec 07, 2020 at 09:37:45PM +0800, Chen Wang wrote:
> Hello,
> I confugure and make musl with following:
> 
> CFLAGS=-g CROSS_COMPILE=riscv64-unknown-linux-gnu- ./configure --prefix=/home/u/ws/musl/install --exec-prefix=/home/u/ws/musl/install --syslibdir=/home/u/ws/musl/install
> 
> create the executable with: ./install/bin/musl-gcc -g test.c

I can't say conclusively that you can't make this work, but you really
don't want to do it this way. musl-gcc is for repurposing the host gcc
on a glibc-based system for "trying out" musl and making minimal
programs. It doesn't make sense to build a glibc-targeting cross
compiler then use musl-gcc to try to repurpose it. Just build a proper
musl-targeting cross-compiler.

However this probably isn't your problem.

> Then I tried to debug:
> $ qemu-riscv64 -g 1234 ./a.out
> then launch gdb:
> $ riscv64-unknown-linux-gnu-gdb a.out
> 
> but after I tried to target remote, gdb oops and tell me:
> ```
> gdb) target remote:1234
> Remote debugging using :1234
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> 0x0000004000850ae2 in ?? ()
> ```
> 
> I tried to set sysroot but does NOT take effect:
> ```
> (gdb) set sysroot /home/u/ws/musl/install/
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> (gdb) set sysroot /home/u/ws/musl/install/lib
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> ```
> I checked the a.out
> ```
> $ riscv64-unknown-linux-gnu-readelf -l a.out
> ......
>   INTERP         0x00000000000001c8 0x00000000000101c8 0x00000000000101c8
>                  0x000000000000002d 0x000000000000002d  R      0x1
>       [Requesting program interpreter: /home/u/ws/musl/install/ld-musl-riscv64.so.1]
> ......
> ```
> And I can run with qemu directly: $ qemu-riscv64 ./a.out, this
> works, but why I can not debug with gdb? Who can help me out? Thanks
> in adv.

I haven't used gdb remote with qemu so I'm not sure what to expect
here in terms of how it finds/loads the binary and dynamic linker
(does it do that over the remote interface or via the local fs?). If
you can enable more output from qemu or strace one or both of gdb and
qemu it might help figure out what's going on.

Hopefully someone else who's use gdb this way can offer more useful
help.

Rich

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [musl] [QUESTION] how to gdb dynamic linker for musl?
  2020-12-07 16:46 ` Rich Felker
@ 2020-12-08  0:55   ` Chen Wang
  2020-12-08  2:34   ` Chen Wang
  1 sibling, 0 replies; 4+ messages in thread
From: Chen Wang @ 2020-12-08  0:55 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 6254 bytes --]

Hi, Rich, thanks for your feedback.
I feel a bit confused about the first comment from you. What's your meaning of "It doesn't make sense to build a glibc-targeting cross compiler then use musl-gcc to try to repurpose it."? I think I'm following the guide from musl user-manual. What's the problem with my operation?
I am building a cross-compile with a risc-v gcc and using musl-gcc to create executable for risc-v. I have created static-linked and dynamic-linked by this way and seems it can work and run on qemu-riscv.

Following is what gcc tells me when I added "-v"

$ $ ./install/bin/musl-gcc -v hello.c 
...... 
 /opt/riscv64/libexec/gcc/riscv64-unknown-linux-gnu/10.1.0/collect2 -plugin /opt/riscv64/libexec/gcc/riscv64-unknown-linux-gnu/10.1.0/liblto_plugin.so -plugin-opt=/opt/riscv64/libexec/gcc/riscv64-unknown-linux-gnu/10.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccyYnEJ8.res -plugin-opt=-pass-through=/opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc.a -plugin-opt=-pass-through=/opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc_eh.a -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=/opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc.a -plugin-opt=-pass-through=/opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc_eh.a -dynamic-linker /home/u/ws/test-musl-shared/install/ld-musl-riscv64.so.1 -nostdlib /home/u/ws/test-musl-shared/install/lib/Scrt1.o /home/u/ws/test-musl-shared/install/lib/crti.o /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/crtbeginS.o -L/home/u/ws/test-musl-shared/install/lib -L /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/. /tmp/cc4bazH8.o /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc.a /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc_eh.a -lc /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc.a /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc_eh.a /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/crtendS.o /home/u/ws/test-musl-shared/install/lib/crtn.o

$ ./install/bin/musl-gcc -v -static hello.c 
......
/opt/riscv64/libexec/gcc/riscv64-unknown-linux-gnu/10.1.0/collect2 -plugin /opt/riscv64/libexec/gcc/riscv64-unknown-linux-gnu/10.1.0/liblto_plugin.so -plugin-opt=/opt/riscv64/libexec/gcc/riscv64-unknown-linux-gnu/10.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccCghbot.res -plugin-opt=-pass-through=/opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc.a -plugin-opt=-pass-through=/opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc_eh.a -plugin-opt=-pass-through=-lc -dynamic-linker /home/u/ws/test-musl-shared/install/ld-musl-riscv64.so.1 -nostdlib -static /home/u/ws/test-musl-shared/install/lib/Scrt1.o /home/u/ws/test-musl-shared/install/lib/crti.o /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/crtbeginS.o -L/home/u/ws/test-musl-shared/install/lib -L /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/. /tmp/ccLHqUru.o --start-group /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc.a /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/libgcc_eh.a -lc --end-group /opt/riscv64/lib/gcc/riscv64-unknown-linux-gnu/10.1.0/crtendS.o /home/u/ws/test-musl-shared/install/lib/crtn.o


Another question is, how you test and debug musl, expecially the dynamic-linker on cross-arch, i.e, debug on x86 machine but for risc-v?  Do you use qemu?  I really want to hear your suggestion. Thanks in adv.




Best Regards

Wang Chen
 
From: Rich Felker
Date: 2020-12-08 00:46
To: Chen Wang
CC: musl
Subject: Re: [musl] [QUESTION] how to gdb dynamic linker for musl?
On Mon, Dec 07, 2020 at 09:37:45PM +0800, Chen Wang wrote:
> Hello,
> I confugure and make musl with following:
> 
> CFLAGS=-g CROSS_COMPILE=riscv64-unknown-linux-gnu- ./configure --prefix=/home/u/ws/musl/install --exec-prefix=/home/u/ws/musl/install --syslibdir=/home/u/ws/musl/install
> 
> create the executable with: ./install/bin/musl-gcc -g test.c
 
I can't say conclusively that you can't make this work, but you really
don't want to do it this way. musl-gcc is for repurposing the host gcc
on a glibc-based system for "trying out" musl and making minimal
programs. It doesn't make sense to build a glibc-targeting cross
compiler then use musl-gcc to try to repurpose it. Just build a proper
musl-targeting cross-compiler.
 
However this probably isn't your problem.
 
> Then I tried to debug:
> $ qemu-riscv64 -g 1234 ./a.out
> then launch gdb:
> $ riscv64-unknown-linux-gnu-gdb a.out
> 
> but after I tried to target remote, gdb oops and tell me:
> ```
> gdb) target remote:1234
> Remote debugging using :1234
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> 0x0000004000850ae2 in ?? ()
> ```
> 
> I tried to set sysroot but does NOT take effect:
> ```
> (gdb) set sysroot /home/u/ws/musl/install/
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> (gdb) set sysroot /home/u/ws/musl/install/lib
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> ```
> I checked the a.out
> ```
> $ riscv64-unknown-linux-gnu-readelf -l a.out
> ......
>   INTERP         0x00000000000001c8 0x00000000000101c8 0x00000000000101c8
>                  0x000000000000002d 0x000000000000002d  R      0x1
>       [Requesting program interpreter: /home/u/ws/musl/install/ld-musl-riscv64.so.1]
> ......
> ```
> And I can run with qemu directly: $ qemu-riscv64 ./a.out, this
> works, but why I can not debug with gdb? Who can help me out? Thanks
> in adv.
 
I haven't used gdb remote with qemu so I'm not sure what to expect
here in terms of how it finds/loads the binary and dynamic linker
(does it do that over the remote interface or via the local fs?). If
you can enable more output from qemu or strace one or both of gdb and
qemu it might help figure out what's going on.
 
Hopefully someone else who's use gdb this way can offer more useful
help.
 
Rich

[-- Attachment #2: Type: text/html, Size: 9491 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [musl] [QUESTION] how to gdb dynamic linker for musl?
  2020-12-07 16:46 ` Rich Felker
  2020-12-08  0:55   ` Chen Wang
@ 2020-12-08  2:34   ` Chen Wang
  1 sibling, 0 replies; 4+ messages in thread
From: Chen Wang @ 2020-12-08  2:34 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 4930 bytes --]

Regarding the setup of gdb cross-debugging env, I find a solution and summarize here just FYI. If you have more questions or better idea please feel free let me know.

First compile musl:
```
$ CFLAGS=-g CROSS_COMPILE=riscv64-unknown-linux-gnu- ./configure --prefix=/home/u/ws/test-musl-shared/install --exec-prefix=/home/u/ws/test-musl-shared/install
```
notice I use `CFLAGS=-g` to enable debug info, but not `--enable-debug`, I just find if I use `--enable-debug` instead, when I install the musl, the folder bin would not be created. I'm testing with musl-1.2.1, not sue if it is a bug.

After installation is completed, enter install/lib folder and create a symbol link for libc.so, the command you can input is `ln -s ./libc.so ld-musl-riscv64.so.1`. Use this link-name just match the interpreter path name in executale we would create later. The purpose of what I do here is to use the install folder as sysroot for later gdb debugging. 

Build a simple hello a.out
`./install/bin/musl-gcc -g hello.c`

Check it's elf info and look at the interpreter info here.
```
$ riscv64-unknown-linux-gnu-readelf -l a.out
......
  INTERP         0x00000000000001c8 0x00000000000101c8 0x00000000000101c8
                 0x000000000000001a 0x000000000000001a  R      0x1
      [Requesting program interpreter: /lib/ld-musl-riscv64.so.1]
......
```

Now we can launch gdb to do cross-debug:
Run gdb-server: `$ qemu-riscv64 -L /home/u/ws/test-musl-shared/install -g 1234 ./a.out`
Run gdb-client and set sysroot as the install folder so gdb can load symbols from our libc.so successfully.
``` 
$ riscv64-unknown-linux-gnu-gdb a.out
GNU gdb (GDB) 9.1
......
Reading symbols from a.out...
(gdb) show sysroot
The current system root is "/opt/riscv64/sysroot".
(gdb) set sysroot /home/u/ws/test-musl-shared/install
(gdb) target remote:1234
Remote debugging using :1234
Reading symbols from /home/u/ws/test-musl-shared/install/lib/ld-musl-riscv64.so.1...
0x0000004000850ae2 in _dlstart () from /home/u/ws/test-musl-shared/install/lib/ld-musl-riscv64.so.1
```

That's all.





Best Regards

Wang Chen
 
From: Rich Felker
Date: 2020-12-08 00:46
To: Chen Wang
CC: musl
Subject: Re: [musl] [QUESTION] how to gdb dynamic linker for musl?
On Mon, Dec 07, 2020 at 09:37:45PM +0800, Chen Wang wrote:
> Hello,
> I confugure and make musl with following:
> 
> CFLAGS=-g CROSS_COMPILE=riscv64-unknown-linux-gnu- ./configure --prefix=/home/u/ws/musl/install --exec-prefix=/home/u/ws/musl/install --syslibdir=/home/u/ws/musl/install
> 
> create the executable with: ./install/bin/musl-gcc -g test.c
 
I can't say conclusively that you can't make this work, but you really
don't want to do it this way. musl-gcc is for repurposing the host gcc
on a glibc-based system for "trying out" musl and making minimal
programs. It doesn't make sense to build a glibc-targeting cross
compiler then use musl-gcc to try to repurpose it. Just build a proper
musl-targeting cross-compiler.
 
However this probably isn't your problem.
 
> Then I tried to debug:
> $ qemu-riscv64 -g 1234 ./a.out
> then launch gdb:
> $ riscv64-unknown-linux-gnu-gdb a.out
> 
> but after I tried to target remote, gdb oops and tell me:
> ```
> gdb) target remote:1234
> Remote debugging using :1234
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> 0x0000004000850ae2 in ?? ()
> ```
> 
> I tried to set sysroot but does NOT take effect:
> ```
> (gdb) set sysroot /home/u/ws/musl/install/
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> (gdb) set sysroot /home/u/ws/musl/install/lib
> warning: Unable to find dynamic linker breakpoint function.
> GDB will be unable to debug shared library initializers
> and track explicitly loaded dynamic code.
> ```
> I checked the a.out
> ```
> $ riscv64-unknown-linux-gnu-readelf -l a.out
> ......
>   INTERP         0x00000000000001c8 0x00000000000101c8 0x00000000000101c8
>                  0x000000000000002d 0x000000000000002d  R      0x1
>       [Requesting program interpreter: /home/u/ws/musl/install/ld-musl-riscv64.so.1]
> ......
> ```
> And I can run with qemu directly: $ qemu-riscv64 ./a.out, this
> works, but why I can not debug with gdb? Who can help me out? Thanks
> in adv.
 
I haven't used gdb remote with qemu so I'm not sure what to expect
here in terms of how it finds/loads the binary and dynamic linker
(does it do that over the remote interface or via the local fs?). If
you can enable more output from qemu or strace one or both of gdb and
qemu it might help figure out what's going on.
 
Hopefully someone else who's use gdb this way can offer more useful
help.
 
Rich

[-- Attachment #2: Type: text/html, Size: 8112 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-08  2:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07 13:37 [musl] [QUESTION] how to gdb dynamic linker for musl? Chen Wang
2020-12-07 16:46 ` Rich Felker
2020-12-08  0:55   ` Chen Wang
2020-12-08  2:34   ` Chen Wang

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ http://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/musl/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git