Re: clang -pg, libm and the _end symbol
Konstantin Belousovwrites: > On Wed, Feb 24, 2016 at 01:54:25PM +0100, Dimitry Andric wrote: >> On 24 Feb 2016, at 12:27, Raphael Kubo da Costa wrote: >> > >> > I'm reviewing an update to the textproc/miller port in bug 207194, and >> > noticed it does some ugly things in post-configure to seemingly >> > work around the following problem (on 11-HEAD at least): >> > >> > % echo 'int main(void) { return 0; }' > foo.c >> > % clang -pg foo.c -lm >> > /usr/bin/ld: undefined reference to symbol `_end' (try adding -lc) >> > //lib/libc.so.7: could not read symbols: Bad value >> > cc: error: linker command failed with exit code 1 (use -v to see >> > invocation) >> >> Try using: clang -pg foo.c -lm_p >> >> That works for me (also with gcc). > > It probably not quite works, in the sense that it resolves _end to > something not correctly provided by libm_p.a. In other words, sbrk(), > if used for anything, would be broken. It at least "works" in the sense that clang doesn't fail; however, in addition to kib's point this doesn't look optimal from a ports perspective, as it requires giving special treatment to certain targets and possibly hacking the build system in different ports. ___ freebsd-toolchain@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain To unsubscribe, send any mail to "freebsd-toolchain-unsubscr...@freebsd.org"
Re: clang -pg, libm and the _end symbol
On Wed, Feb 24, 2016 at 01:54:25PM +0100, Dimitry Andric wrote: > On 24 Feb 2016, at 12:27, Raphael Kubo da Costawrote: > > > > I'm reviewing an update to the textproc/miller port in bug 207194, and > > noticed it does some ugly things in post-configure to seemingly > > work around the following problem (on 11-HEAD at least): > > > > % echo 'int main(void) { return 0; }' > foo.c > > % clang -pg foo.c -lm > > /usr/bin/ld: undefined reference to symbol `_end' (try adding -lc) > > //lib/libc.so.7: could not read symbols: Bad value > > cc: error: linker command failed with exit code 1 (use -v to see > > invocation) > > Try using: clang -pg foo.c -lm_p > > That works for me (also with gcc). It probably not quite works, in the sense that it resolves _end to something not correctly provided by libm_p.a. In other words, sbrk(), if used for anything, would be broken. ___ freebsd-toolchain@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain To unsubscribe, send any mail to "freebsd-toolchain-unsubscr...@freebsd.org"
Re: clang -pg, libm and the _end symbol
On 24 Feb 2016, at 12:27, Raphael Kubo da Costawrote: > > I'm reviewing an update to the textproc/miller port in bug 207194, and > noticed it does some ugly things in post-configure to seemingly > work around the following problem (on 11-HEAD at least): > > % echo 'int main(void) { return 0; }' > foo.c > % clang -pg foo.c -lm > /usr/bin/ld: undefined reference to symbol `_end' (try adding -lc) > //lib/libc.so.7: could not read symbols: Bad value > cc: error: linker command failed with exit code 1 (use -v to see > invocation) Try using: clang -pg foo.c -lm_p That works for me (also with gcc). -Dimitry signature.asc Description: Message signed with OpenPGP using GPGMail
Re: clang -pg, libm and the _end symbol
On Wed, Feb 24, 2016 at 12:27:03PM +0100, Raphael Kubo da Costa wrote: > I'm reviewing an update to the textproc/miller port in bug 207194, and > noticed it does some ugly things in post-configure to seemingly > work around the following problem (on 11-HEAD at least): > > % echo 'int main(void) { return 0; }' > foo.c > % clang -pg foo.c -lm > /usr/bin/ld: undefined reference to symbol `_end' (try adding -lc) > //lib/libc.so.7: could not read symbols: Bad value > cc: error: linker command failed with exit code 1 (use -v to see > invocation) > > (FWIW, using another library such as -lz instead of -lm retuls in the > same problem) > > Adding LDFLAGS+=-lc to the port's Makefile would've been enough, but I'm > not sure if it'd be just working around an actual bug, plus libtool > automatically strips -lc from the linker invocation: > > 7534 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) > 7535 # Do not include libc due to us having libc/libc_r. > 7536 test X-lc = "X$arg" && continue > > The port builds and links fine on 9.3 without any workarounds, and if I > explicitly use ld.gold to link the above file it also works on HEAD. > > Is clang working as expected or is this a bug? This is probably not a clang bug, but could be. More likely it is ld problem. I do not want to dig into the issue, but I can provide you some points to look at further. The _end symbol is magic, it is defined as the address of the last byte + 1 of zero-initialized data section (.bss). But the symbol is not provided by any object file participating in the linkage of the binary, instead it is created by the linker after all sections are combined in the segments and segments are laid out. The symbol is creation requested by the linker script, look at the /usr/libdata/ldscripts for them, first line of the file contains comment explaining which final binary format is served by the each script. We are aware that binutils 2.25.1 ld for aarch64 has bug where _end is not exported from executable, I was not able to track the bug. To diagnose your issue, look up which linker script is used for -pg linking, look for the _end symbol there. If it is properly requested, then the bug is in base linker. ___ freebsd-toolchain@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain To unsubscribe, send any mail to "freebsd-toolchain-unsubscr...@freebsd.org"
clang -pg, libm and the _end symbol
I'm reviewing an update to the textproc/miller port in bug 207194, and noticed it does some ugly things in post-configure to seemingly work around the following problem (on 11-HEAD at least): % echo 'int main(void) { return 0; }' > foo.c % clang -pg foo.c -lm /usr/bin/ld: undefined reference to symbol `_end' (try adding -lc) //lib/libc.so.7: could not read symbols: Bad value cc: error: linker command failed with exit code 1 (use -v to see invocation) (FWIW, using another library such as -lz instead of -lm retuls in the same problem) Adding LDFLAGS+=-lc to the port's Makefile would've been enough, but I'm not sure if it'd be just working around an actual bug, plus libtool automatically strips -lc from the linker invocation: 7534 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) 7535 # Do not include libc due to us having libc/libc_r. 7536 test X-lc = "X$arg" && continue The port builds and links fine on 9.3 without any workarounds, and if I explicitly use ld.gold to link the above file it also works on HEAD. Is clang working as expected or is this a bug? ___ freebsd-toolchain@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain To unsubscribe, send any mail to "freebsd-toolchain-unsubscr...@freebsd.org"