Skip to content

[FreeBSD] Fix a few issues #12528

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

Merged
merged 3 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,11 @@ function(add_swift_library name)
if("${sdk}" STREQUAL "ANDROID")
list(APPEND swiftlib_private_link_libraries_targets
"-latomic")
# the same issue on FreeBSD, missing symbols:
# __atomic_store, __atomic_compare_exchange, __atomic_load
elseif("${sdk}" STREQUAL "FREEBSD")
list(APPEND swiftlib_private_link_libraries_targets
"${SWIFTLIB_DIR}/clang/lib/freebsd/libclang_rt.builtins-${arch}.a")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a very specific path to hardcode, but I'll take your word for it that it's a reasonable. (Especially for a CMake section we'd like to clean up later.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hard-coded path does not work on my build. The .a file has been moved to build/Ninja-ReleaseAssert/llvm-freebsd-x86_64/lib/clang/5.0.0/lib/freebsd/libclang_rt.builtins-${arch}.a.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ${SWIFTLIB_DIR}/clang should be a symlink to lib/clang/5.0.0, so if you're seeing issues here, something else has gone wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if you haven't built in a long time, the Clang version of the symlink may not match the actual Clang version.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I checked and the symlink is there and correct. I wonder why cmake doesn't follow it...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I commented out these lines and swift built just fine. So it might be the case that they can be removed in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible you just weren't using anything (from C) that needed atomics.

endif()
elseif("${lib}" STREQUAL "ICU_I18N")
list(APPEND swiftlib_private_link_libraries_targets
Expand Down
11 changes: 8 additions & 3 deletions stdlib/public/runtime/ImageInspectionELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <link.h>
#include <string.h>

#if defined(__ANDROID__)
#if defined(__ANDROID__) || defined(__FreeBSD__)
#include "llvm/ADT/StringRef.h"
#endif

Expand Down Expand Up @@ -72,9 +72,14 @@ static SectionInfo getSectionInfo(const char *imageName,
SectionInfo sectionInfo = { 0, nullptr };
void *handle = dlopen(imageName, RTLD_LAZY | RTLD_NOLOAD);
if (!handle) {
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(__FreeBSD__)
#if defined(__ANDROID__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not extremely happy about this macro dance but it seems consistent with what's there (and probably OK).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary on FreeBSD? It is necessary on Android because the OS hides the contents of /system/lib from dlopen().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the reasons but this part is called and fails with /libexec/ld-elf.so.1 and then with the main executable path. As for the latter, from #10836 (comment) I assumed that dl_iterate_phdr has the same behavior on FreeBSD.

const char *systemPath = "/system/lib";
Copy link
Contributor

@johnno1962 johnno1962 Oct 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you could change this to “/system” while you’re in the neighbourhood as there are libraries that are blocked in “/system/vendor” as well as “/system/lib" on some devices. None of these libraries will have Swift implementations to worry about conformance for. Saves us all a PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-/ Let's not mix FreeBSD and Android changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-/

#elif defined(__FreeBSD__)
const char *systemPath = "/libexec";
#endif
llvm::StringRef imagePath = llvm::StringRef(imageName);
if (imagePath.startswith("/system/lib") ||
if (imagePath.startswith(systemPath) ||
(imageName && !imagePath.endswith(".so"))) {
return sectionInfo;
}
Expand Down
4 changes: 2 additions & 2 deletions utils/build-script-impl
Original file line number Diff line number Diff line change
Expand Up @@ -3448,8 +3448,8 @@ function build_and_test_installable_package() {
with_pushd "${host_install_destdir}" \
call tar -c -z -f "${package_for_host}" "${TOOLCHAIN_PREFIX/#\/}"
else
# tar on OS X doesn't support --owner/--group.
if [[ "$(uname -s)" == "Darwin" ]] ; then
# BSD tar doesn't support --owner/--group.
if [[ "$(uname -s)" == "Darwin" || "$(uname -s)" == "FreeBSD" ]] ; then
with_pushd "${host_install_destdir}" \
tar -c -z -f "${package_for_host}" "${host_install_prefix/#\/}"
else
Expand Down