This is an archive of the discontinued LLVM Phabricator instance.

Do not pass an explicit reexported symbol list when building libc++ dylib if also defining new/delete
ClosedPublic

Authored by mehdi_amini on Mar 22 2017, 5:21 PM.

Details

Reviewers
EricWF
Summary

The linker would fail because the list of reexported symbols contains new/delete operators.

Diff Detail

Event Timeline

mehdi_amini created this revision.Mar 22 2017, 5:21 PM
EricWF edited edge metadata.Mar 27 2017, 7:43 PM

I'm a bit confused by the description of this change. Libc++ has been enabling the new/delete definitions in its dylib since forever and I've never experienced a link error. Did you mean to say the link error occurs only when libc++abi doesn't define them?

I'm a bit confused by the description of this change. Libc++ has been enabling the new/delete definitions in its dylib since forever and I've never experienced a link error. Did you mean to say the link error occurs only when libc++abi doesn't define them?

Most people have the "command line tools" package installed on macOS, and it means that you're taking this condition:

if (DEFINED CMAKE_OSX_SYSROOT AND NOT CMAKE_OSX_SYSROOT STREQUAL "")

which leads you to:

-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib

While the GreenDragon bots don't have the command line tools, so CMAKE_OSX_SYSROOT is defined by cmake and then this is used instead:

set(OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")

Not that I'm claiming to understand why we're changing strategy when we have the command line tools installed or not in this case ;)

(CC @beanz if he know by any chance!)

I'm a bit confused by the description of this change. Libc++ has been enabling the new/delete definitions in its dylib since forever and I've never experienced a link error. Did you mean to say the link error occurs only when libc++abi doesn't define them?

Most people have the "command line tools" package installed on macOS, and it means that you're taking this condition:

if (DEFINED CMAKE_OSX_SYSROOT AND NOT CMAKE_OSX_SYSROOT STREQUAL "")

which leads you to:

-Wl,-reexport_library,${CMAKE_OSX_SYSROOT}/usr/lib/libc++abi.dylib

While the GreenDragon bots don't have the command line tools, so CMAKE_OSX_SYSROOT is defined by cmake and then this is used instead:

set(OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp")

I think you have that reversed. I have command line tools installed and CMAKE_OSX_SYSROOT isn't defined. Therefore the else() branch is taken and libc++abi is exported via the ABI list.

Strange. So installing the command line tools is not enough. It has to be that CMAKE_OSX_SYSROOT is only defined on Apple internal install maybe?

Anyway, if you're exporting through the ABI list and have LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS I expect the link to fail. You're not observing this?

I have this error:

ld: requested re-export symbol operator new(unsigned long) is not from a dylib, but from lib/CMakeFiles/cxx_objects.dir/__/src/new.cpp.o
 file 'lib/CMakeFiles/cxx_objects.dir/__/src/new.cpp.o' for architecture x86_64

I can reproduce with: cmake -GNinja -DCMAKE_OSX_SYSROOT="" path/to/libcxx

Strange. So installing the command line tools is not enough. It has to be that CMAKE_OSX_SYSROOT is only defined on Apple internal install maybe?

Are you sure you're starting with a clean CMake build directory?

Anyway, if you're exporting through the ABI list and have LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS I expect the link to fail. You're not observing this?

I am not observing this, and LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS is ON. I also added -DCMAKE_OSX_SYSROOT="" but that had no effect as I would expect.

I have this error:

ld: requested re-export symbol operator new(unsigned long) is not from a dylib, but from lib/CMakeFiles/cxx_objects.dir/__/src/new.cpp.o
 file 'lib/CMakeFiles/cxx_objects.dir/__/src/new.cpp.o' for architecture x86_64

Interesting. That seems to suggest that libc++abi.dylib doesn't provide the definition at all. Not necessarily that
the duplicate definitions are causing this.

I can reproduce with: cmake -GNinja -DCMAKE_OSX_SYSROOT="" path/to/libcxx

Here is the script I use to build libc++ on https://gist.github.com/EricWF/0bc0ba09b8844d0201b18a01f8f7ffb9.

Strange. So installing the command line tools is not enough. It has to be that CMAKE_OSX_SYSROOT is only defined on Apple internal install maybe?

Are you sure you're starting with a clean CMake build directory?

Yes. But now that I think about it, I'm using an internal branch, the issue has to come from that. I'll look deeper tomorrow!

I have this error:

ld: requested re-export symbol operator new(unsigned long) is not from a dylib, but from lib/CMakeFiles/cxx_objects.dir/__/src/new.cpp.o
 file 'lib/CMakeFiles/cxx_objects.dir/__/src/new.cpp.o' for architecture x86_64

Interesting. That seems to suggest that libc++abi.dylib doesn't provide the definition at all. Not necessarily that
the duplicate definitions are causing this.

I think it says that the list of reexport explicitly mentions a symbol that comes from an object (new.cpp.o) and not another dylib. This error will happens whether the symbol is also in libc++abi or not.

OK, I figured, it is because I have this revision locally on top of this one: https://reviews.llvm.org/D30765 ; and I can't submit the latter without the change here.

EricWF accepted this revision.Mar 29 2017, 6:34 PM
EricWF added inline comments.
lib/CMakeLists.txt
155

Please explain that the linker will fail because libc++abi also provides those definitions.

This revision is now accepted and ready to land.Mar 29 2017, 6:34 PM
mehdi_amini added inline comments.Mar 29 2017, 9:52 PM
lib/CMakeLists.txt
155

Mmmm, actually no, the linker fails because libc++ provide those definition.
The linker complains because we can't ask to export the definitions from libc++abi while we already have some definitions!

mehdi_amini closed this revision.Mar 29 2017, 9:58 PM

r299052 ; let me know if you want to improve the comment in any way.