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

[FreeBSD] Fix a few issues #12528

merged 3 commits into from
Oct 27, 2017

Conversation

antonmes
Copy link
Contributor

@antonmes antonmes commented Oct 20, 2017

This PR fixes a few issues on FreeBSD 11 / 12

  1. creation of installable .tar.gz package
  2. libswiftCore.so: undefined reference to
    __atomic_store __atomic_compare_exchange __atomic_load *
  3. crash of produced executables: dlopen() failed on ./main: (NULL)Abort (core dumped)

Related issues: #10836 (comment)

* Couldn't find a better way.

@dcci
Copy link
Member

dcci commented Oct 20, 2017

@swift-ci please test

@dcci
Copy link
Member

dcci commented Oct 20, 2017

The FreeBSD bits look good to me but please wait for explicit approval by somebody on the swift team before merging.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8ffd8933b959b1d78e41b4e4fc2acddb88dac1df

@dcci
Copy link
Member

dcci commented Oct 20, 2017

@antonmes your code is failing on Linux, PTAL.

@antonmes
Copy link
Contributor Author

@dcci I think it's not related to the PR, something with swift-corelibs-foundation in regression tests. Swift itself passes all the tests. This additions shouldn't affect any Darwin or Linux build instructions.

@@ -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.

@@ -1528,7 +1528,10 @@ function(add_swift_library name)
"${SWIFT_${sdk}_ICU_UC}")
# temporary fix for atomic needing to be
# after object files for libswiftCore.so
if("${sdk}" STREQUAL "ANDROID")
if("${sdk}" STREQUAL "FREEBSD")
list(APPEND swiftlib_private_link_libraries_targets
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a comment here explaining why we need this?

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 thought the existing comment is enough, it's the same issue but we use builtins instead of -latomic. I don't know how to explain this or the reason. 😊

Copy link
Contributor

@gparker42 gparker42 Oct 20, 2017

Choose a reason for hiding this comment

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

You should update the comment, then, to mention builtins in addition to atomic.

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 mean it imports __atomic_store __atomic_compare_exchange __atomic_load from builtins. should i just list them there?

@dcci
Copy link
Member

dcci commented Oct 20, 2017

You probably need to wait until the failure goes away, rebase on top of master and retry. Some minors, otherwise I think this is fine.

@antonmes
Copy link
Contributor Author

@swift-ci please smoke test

@dcci
Copy link
Member

dcci commented Oct 21, 2017

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8ffd8933b959b1d78e41b4e4fc2acddb88dac1df

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8ffd8933b959b1d78e41b4e4fc2acddb88dac1df

# __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.

@jrose-apple
Copy link
Contributor

If @gparker42 has no further objections then I think this can go in. It's certainly not going to break anyone else.

#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(__FreeBSD__)
#if defined(__ANDROID__)
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.

:-/

@gparker42
Copy link
Contributor

Looks good. @dcci?

@dcci
Copy link
Member

dcci commented Oct 27, 2017

LGTM, thanks!

@gparker42 gparker42 merged commit e39f82f into swiftlang:master Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants