Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On macOS, strip=symbols results in "error: symbols referenced by indirect symbol table entries that can't be stripped in <file>.dylib" #93988

Closed
edmorley opened this issue Feb 14, 2022 · 2 comments · Fixed by #97991
Labels
C-bug Category: This is a bug.

Comments

@edmorley
Copy link
Contributor

edmorley commented Feb 14, 2022

When the new strip codegen option is used on OS X with mode "symbols" (which is the highest strip mode, and what is used when strip=true is passed to Cargo), the build emits the following warning for the testcase below:

   Compiling libcnb-proc-macros v0.1.1 (/Users/emorley/src/libcnb.rs/libcnb-proc-macros)
warning: stripping debug info with `strip` failed: exit status: 1
  |
  = note: /Library/Developer/CommandLineTools/usr/bin/strip: error: symbols referenced by indirect symbol table entries that can't be stripped in: /Users/emorley/src/testcase/target/release/deps/liblibcnb_proc_macros-5b9f8927d4ae103e.dylib

Doing any of the following stops the warning from appearing (see the workarounds section below for more details):

  • Setting strip to "debuginfo" instead of "symbols" (globally).
  • Setting a build-override for strip, to turn it off for proc-macros/... only, whilst leaving it set to "symbols" for everything else.
  • Changing the dependency in the testcase below from a local path reference to the published crate. (The published crate is identical to the local version, so this seems significant?)

This potentially seems like fallout from #88137 - cc @joshtriplett


Steps to reproduce

  1. git clone https://github.com/Malax/libcnb.rs (currently at 11bdefc02d649fdde3ac5c1404e7d8d5f8f2681c)
  2. cargo new testcase && cd $_
  3. cargo add ../libcnb.rs/libcnb-proc-macros
  4. CARGO_PROFILE_RELEASE_STRIP=symbols cargo build --release

Expected

The cargo build completes successfully (exit code 0), with no warnings/errors seen in the build output.

Actual

Whilst the build completes successfully (exit code 0), there is a warning/error about stripping in the build output. Ideally rustc would configure stripping so it "just works" with one of the presets like "symbols", or else suppress warnings if they are deemed expected in certain scenarios.

$ CARGO_PROFILE_RELEASE_STRIP=symbols cargo build --release
   Compiling memchr v2.4.1
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.86
   Compiling regex-syntax v0.6.25
   Compiling bit-vec v0.6.3
   Compiling bit-set v0.5.2
   Compiling aho-corasick v0.7.18
   Compiling quote v1.0.15
   Compiling regex v1.5.4
   Compiling fancy-regex v0.7.1
   Compiling libcnb-proc-macros v0.1.1 (/Users/emorley/src/libcnb.rs/libcnb-proc-macros)
warning: stripping debug info with `strip` failed: exit status: 1
  |
  = note: /Library/Developer/CommandLineTools/usr/bin/strip: error: symbols referenced by indirect symbol table entries that can't be stripped in: /Users/emorley/src/testcase/target/release/deps/liblibcnb_proc_macros-5b9f8927d4ae103e.dylib
          __NSGetArgc
          __NSGetArgv
          __NSGetEnviron
          __NSGetExecutablePath
          __Unwind_Backtrace
          __Unwind_DeleteException
          __Unwind_GetCFA
          __Unwind_GetDataRelBase
          __Unwind_GetIP
          __Unwind_GetIPInfo
          __Unwind_GetLanguageSpecificData
          __Unwind_GetRegionStart
          __Unwind_GetTextRelBase
          __Unwind_RaiseException
          __Unwind_Resume
          __Unwind_SetGR
          __Unwind_SetIP
          ___bzero
          ___error
          __dyld_get_image_header
          __dyld_get_image_name
          __dyld_get_image_vmaddr_slide
          __dyld_image_count
          __exit
          __tlv_atexit
          _abort
          _accept
          _bind
          _calloc
          _chdir
          _chmod
          _chown
          _chroot
          _close$NOCANCEL
          _closedir
          _connect
          _copyfile_state_alloc
          _copyfile_state_free
          _copyfile_state_get
          _dlsym
          _dup2
          _execvp
          _exit
          _fchmod
          _fchown
          _fcntl
          _fcopyfile
          _fork
          _free
          _freeaddrinfo
          _fstat$INODE64
          _ftruncate
          _gai_strerror
          _getaddrinfo
          _getcwd
          _getenv
          _getpeereid
          _getpeername
          _getpid
          _getppid
          _getpwuid_r
          _getsockname
          _getsockopt
          _gettimeofday
          _getuid
          _ioctl
          _kill
          _lchown
          _link
          _listen
          _lseek
          _lstat$INODE64
          _mach_absolute_time
          _mach_timebase_info
          _malloc
          _memchr
          _memcmp
          _memcpy
          _memmove
          _memset
          _mkdir
          _mmap
          _mprotect
          _munmap
          _nanosleep
          _open
          _opendir$INODE64
          _pipe
          _poll
          _posix_memalign
          _posix_spawn_file_actions_adddup2
          _posix_spawn_file_actions_destroy
          _posix_spawn_file_actions_init
          _posix_spawnattr_destroy
          _posix_spawnattr_init
          _posix_spawnattr_setflags
          _posix_spawnattr_setsigdefault
          _posix_spawnattr_setsigmask
          _posix_spawnp
          _pread
          _pthread_attr_destroy
          _pthread_attr_init
          _pthread_attr_setstacksize
          _pthread_cond_broadcast
          _pthread_cond_destroy
          _pthread_cond_signal
          _pthread_cond_timedwait
          _pthread_cond_wait
          _pthread_create
          _pthread_detach
          _pthread_get_stackaddr_np
          _pthread_get_stacksize_np
          _pthread_join
          _pthread_key_create
          _pthread_key_delete
          _pthread_mutex_destroy
          _pthread_mutex_init
          _pthread_mutex_lock
          _pthread_mutex_trylock
          _pthread_mutex_unlock
          _pthread_mutexattr_destroy
          _pthread_mutexattr_init
          _pthread_mutexattr_settype
          _pthread_rwlock_destroy
          _pthread_rwlock_rdlock
          _pthread_rwlock_unlock
          _pthread_rwlock_wrlock
          _pthread_self
          _pthread_setname_np
          _pthread_sigmask
          _pwrite
          _read
          _readdir_r$INODE64
          _readlink
          _readv
          _realloc
          _realpath$DARWIN_EXTSN
          _recv
          _recvfrom
          _rename
          _rmdir
          _sched_yield
          _send
          _sendto
          _setenv
          _setgid
          _setgroups
          _setsockopt
          _setuid
          _shutdown
          _sigaction
          _sigaddset
          _sigaltstack
          _sigemptyset
          _signal
          _socket
          _socketpair
          _stat$INODE64
          _strerror_r
          _strlen
          _symlink
          _sysconf
          _unlink
          _unsetenv
          _waitpid
          _write
          _writev

Workarounds

The warning does not appear if...

  • Mode debuginfo is used instead (ie: step 4 replaced with CARGO_PROFILE_RELEASE_STRIP=debuginfo cargo build --release).
  • Strip is switched off for proc-macros (ie: step 4 replaced with CARGO_PROFILE_RELEASE_STRIP=symbols CARGO_PROFILE_RELEASE_BUILD_OVERRIDE=none cargo build --release)
  • The libcnb-proc-macros dependency is changed from a local path reference to the published crate (ie: step 3 changed to cargo add libcnb-proc-macros@0.1.1) - even though the published crate is identical to the local version?!

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (1e12aef3f 2022-02-13)
binary: rustc
commit-hash: 1e12aef3fab243407f9d71ba9956cb2a1bf105d5
commit-date: 2022-02-13
host: x86_64-apple-darwin
release: 1.60.0-nightly
LLVM version: 13.0.0
@ehuss
Copy link
Contributor

ehuss commented Feb 17, 2022

This happens with any proc-macro, it is not unique to libcnb-proc-macros.

The reason it only happens with path-based dependencies is because registry dependencies suppress warnings from being displayed.

I believe the issue is that bare strip is too aggressive for a dylib. strip -u seems to work. I'm not sure if -r should also be added. I might suggest adding -u to any dylib crate. The relevant code is around here.

cc @joshtriplett FYI

@ehuss
Copy link
Contributor

ehuss commented Feb 17, 2022

Hm, I think it's actually -x is what should be used for dylibs:

From the man page:

For dynamic shared libraries, the maximum level of stripping is usually -x (to remove all non-global symbols).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants