Bug 440016 - Build error: undefined reference to `sleep'
Summary: Build error: undefined reference to `sleep'
Status: RESOLVED NOT A BUG
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-18 20:53 UTC by Adam Stewart
Modified: 2021-07-18 22:41 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
Build log (448.92 KB, text/plain)
2021-07-18 20:53 UTC, Adam Stewart
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Stewart 2021-07-18 20:53:40 UTC
Created attachment 140167 [details]
Build log

SUMMARY

I'm trying to compile valgrind 3.17.0 but I'm encountering a build error.

STEPS TO REPRODUCE
1. configure --enable-ubsan --enable-only64bit
2. make

OBSERVED RESULT

The build error looks like:

../coregrind/link_tool_exe_linux 0x58000000 /mnt/a/u/sciteam/stewart1/spack/lib/spack/env/gcc/gcc     -o memcheck-amd64-linux  -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-signedness -Wformat-security -Wignored-qualifiers -Wmissing-parameter-type -Wlogical-op -Wimplicit-fallthrough=2 -Wold-style-declaration -finline-functions -fno-stack-protector -fsanitize=undefined -fno-sanitize=alignment -fno-strict-aliasing -fno-builtin  -fomit-frame-pointer -O2 -static -nodefaultlibs -nostartfiles -u _start -Wl,--build-id=none -m64 memcheck_amd64_linux-mc_leakcheck.o memcheck_amd64_linux-mc_malloc_wrappers.o memcheck_amd64_linux-mc_main.o memcheck_amd64_linux-mc_main_asm.o memcheck_amd64_linux-mc_translate.o memcheck_amd64_linux-mc_machine.o memcheck_amd64_linux-mc_errors.o ../coregrind/libcoregrind-amd64-linux.a ../VEX/libvex-amd64-linux.a -lgcc ../coregrind/libgcc-sup-amd64-linux.a
/opt/cray/atp/2.0.4/libApp/libAtpSigHandler.a(atpSigHandler.o): In function `mySleep':
atpSigHandler.c:(.text+0x59): undefined reference to `sleep'
/opt/cray/atp/2.0.4/libApp/libAtpSigHandler.a(atpSigHandler.o): In function `logAltStack':
atpSigHandler.c:(.text+0xe6): undefined reference to `syscall'
/opt/cray/atp/2.0.4/libApp/libAtpSigHandler.a(atpSigHandler.o): In function `getApid':
atpSigHandler.c:(.text+0x174): undefined reference to `__getpid'
atpSigHandler.c:(.text+0x192): undefined reference to `ioctl'
/opt/cray/atp/2.0.4/libApp/libAtpSigHandler.a(atpSigHandler.o): In function `isEnvVarTrue':
atpSigHandler.c:(.text+0x1cf): undefined reference to `getenv'
/opt/cray/atp/2.0.4/libApp/libAtpSigHandler.a(atpSigHandler.o): In function `defaultEnvVar':
atpSigHandler.c:(.text+0x23b): undefined reference to `getenv'
atpSigHandler.c:(.text+0x252): undefined reference to `atoi'
/opt/cray/atp/2.0.4/libApp/libAtpSigHandler.a(atpSigHandler.o): In function `atpAppSigHandler':
atpSigHandler.c:(.text+0x333): undefined reference to `syscall'
atpSigHandler.c:(.text+0x386): undefined reference to `syscall'
atpSigHandler.c:(.text+0x3a4): undefined reference to `syscall'

EXPECTED RESULT

I would expect things to compile without issue.

SOFTWARE/OS VERSIONS

Linux/KDE Plasma: Cray CNL5
Comment 1 Tom Hughes 2021-07-18 21:39:03 UTC
What is /opt/cray/atp/2.0.4/libApp/libAtpSigHandler.a and why are you trying to link it to valgrind?

That's not a standard part of valgrind, and as valgrind doesn't link with libc you won't be able to link it against anything (like that library) which uses valgrind.

I think there's something very odd about your environment, or how you have configured valgrind, that is causing it to try and link against that library.
Comment 2 Tom Hughes 2021-07-18 21:40:50 UTC
The full log shows that you're using /mnt/a/u/sciteam/stewart1/spack/lib/spack/env/gcc/gcc as your compiler which is obviously not a standard system compiler so maybe that gcc has been configured with unusual defaults that cause it to try and link against that library?
Comment 3 Tom Hughes 2021-07-18 21:43:31 UTC
So this is the link that fails:

../coregrind/link_tool_exe_linux 0x58000000 /mnt/a/u/sciteam/stewart1/spack/lib/spack/env/gcc/gcc     -o memcheck-amd64-linux  -m64 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wcast-align -Wcast-qual -Wwrite-strings -Wempty-body -Wformat -Wformat-signedness -Wformat-security -Wignored-qualifiers -Wmissing-parameter-type -Wlogical-op -Wimplicit-fallthrough=2 -Wold-style-declaration -finline-functions -fno-stack-protector -fsanitize=undefined -fno-sanitize=alignment -fno-strict-aliasing -fno-builtin  -fomit-frame-pointer -O2 -static -nodefaultlibs -nostartfiles -u _start -Wl,--build-id=none -m64 memcheck_amd64_linux-mc_leakcheck.o memcheck_amd64_linux-mc_malloc_wrappers.o memcheck_amd64_linux-mc_main.o memcheck_amd64_linux-mc_main_asm.o memcheck_amd64_linux-mc_translate.o memcheck_amd64_linux-mc_machine.o memcheck_amd64_linux-mc_errors.o ../coregrind/libcoregrind-amd64-linux.a ../VEX/libvex-amd64-linux.a -lgcc ../coregrind/libgcc-sup-amd64-linux.a 

as you can see that never mentions libAtpSigHandler so it seems your gcc is deciding to link against that non-standard library for some reason, even though we specify -nodefaultlibs, which then fails because -nodefaultlibs has, as intended, stopping libc being pulled in.

This seems to be a problem with your toolchain I'm afraid.
Comment 4 Adam Stewart 2021-07-18 21:44:53 UTC
> What is /opt/cray/atp/2.0.4/libApp/libAtpSigHandler.a

No idea.

> why are you trying to link it to valgrind?

I'm not, Autotools is.

> I think there's something very odd about your environment, or how you have configured valgrind, that is causing it to try and link against that library.

Welcome to trying to build software on a Cray supercomputer :)

Things are generally more challenging than necessary on Cray, but all of the other software I'm building seems to be working other than valgrind. I'm not sure how to debug this one.

> The full log shows that you're using /mnt/a/u/sciteam/stewart1/spack/lib/spack/env/gcc/gcc as your compiler which is obviously not a standard system compiler so maybe that gcc has been configured with unusual defaults that cause it to try and link against that library?

I'm using the Spack package manager (https://spack.io). Spack uses compiler wrappers which inject flags like -L and -I based on dependencies. Note that this weird ATP thing that's getting sucked in isn't one of the dependencies.

I'm guessing that this is something to do with the Cray Compiler Environment, not with Spack. Let me try building outside of Spack to see if I can reproduce the issue.
Comment 5 Adam Stewart 2021-07-18 22:08:51 UTC
I think I found the culprit:

$ module show atp
-------------------------------------------------------------------
/opt/cray/modulefiles/atp/2.0.4:

conflict	 atpDebug 
prepend-path	 MANPATH /opt/cray/atp/2.0.4/man 
setenv		 ATP_HOME /opt/cray/atp/2.0.4 
setenv		 ATP_MRNET_COMM_PATH /opt/cray/atp/2.0.4/libexec/atp_mrnet_commnode_wrapper 
setenv		 MPICH_ABORT_ON_ERROR 1 
setenv		 SHMEM_ABORT_ON_ERROR 1 
setenv		 DMAPP_ABORT_ON_ERROR 1 
setenv		 ATP_IGNORE_SIGTERM 1 
append-path	 PKG_CONFIG_PATH /opt/cray/atp/2.0.4/lib/pkgconfig 
prepend-path	 PE_PKGCONFIG_LIBS AtpSigHandler 
setenv		 ATP_POST_LINK_OPTS -Wl,-L/opt/cray/atp/2.0.4/libApp/  
-------------------------------------------------------------------

This module is enabled by default on my system. Let me try unloading it and see if I can build successfully.
Comment 6 Adam Stewart 2021-07-18 22:41:42 UTC
Hmm, even if I unload this module I get the same error. I agree that my environment is broken but I'm not sure how to fix it. Anyway, it doesn't seem like this is a problem with valgrind itself, so we can close this. Thanks for your help!