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

[lldb][cmake] Remove local rpaths from the build host on ELF platforms #6456

Merged
merged 3 commits into from
May 4, 2023

Conversation

finagolfin
Copy link
Member

@finagolfin finagolfin commented Mar 11, 2023

Also, add rpath support for more platforms, like Android and the BSDs.

I'm removing the last references to the CI build in linux runpaths, as in swiftlang/sourcekit-lsp#715, and most of these remaining are in lldb:

> find swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/ -name "lib*\.so*"|xargs readelf -d|ag "File:|runpath"|ag /home/ -B1
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/liblldb.so.13.0.0git
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:$ORIGIN/../lib/swift/linux]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/liblldb.so
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:$ORIGIN/../lib/swift/linux]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicuucswift.so
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicuucswift.so.65
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicudataswift.so
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicui18nswift.so.65.1
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicui18nswift.so.65
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicudataswift.so.65.1
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicudataswift.so.65
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicuucswift.so.65.1
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/swift/linux/libicui18nswift.so
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux/x86_64]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/liblldb.so.13git
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:$ORIGIN/../lib/swift/linux]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/clang/13.0.0/lib/linux/libclang_rt.memprof-x86_64.so
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/lib/clang/13.0.0/lib/linux/libclang_rt.ubsan_minimal-x86_64.so
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib]

> readelf -d swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/bin/*|ag "File:|runpath"|ag /home/ -B1
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/bin/lldb
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/bin/lldb-argdumper
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/bin/lldb-server
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib]
File: swift-DEVELOPMENT-SNAPSHOT-2023-03-10-a-ubuntu20.04/usr/bin/sourcekit-lsp
 0x000000000000001d (RUNPATH)            Library runpath: [/home/build-user/swift-nightly-install/usr/lib/swift/linux:$ORIGIN:$ORIGIN/../lib/swift/linux]

I believe the reason that only the lldb binaries have these /home/build-user/ runpaths is because lldb is built separately by the Swift build, so then the lldb build adds the local build directory to the runpath too.

@eeckstein, please review, since you wrote the add_properties_for_swift_modules() function that I'm modifying here.

@compnerd, would be good to get your CMake input.

elseif(APSM_BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
target_link_directories(${target} PRIVATE "${LLDB_SWIFT_LIBS}/macosx")
set(SWIFT_RPATH "${LLDB_SWIFT_LIBS}/macosx")
set(SWIFT_BUILD_RPATH "${LLDB_SWIFT_LIBS}/macosx")
set(SWIFT_INSTALL_RPATH "${LLDB_SWIFT_LIBS}/macosx")
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if this rpath needs to be set for both the build and install on macOS, but just kept it the same for now.

Choose a reason for hiding this comment

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

Isn't this a change for macOS?

Copy link
Member Author

Choose a reason for hiding this comment

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

It shouldn't be. Currently, SWIFT_RPATH is set as both the build and install rpath for macOS below, whereas I simply use two variables set to the same rpath on macOS after this pull, ie the end result should be the same.

I only had to copy these for macOS because on linux I need to set different build and install rpaths.

set(SWIFT_RPATH "${LLDB_SWIFT_LIBS}/linux;$ORIGIN/../lib/swift/linux")
string(TOLOWER ${CMAKE_SYSTEM_NAME} platform)
set(SWIFT_BUILD_RPATH "${LLDB_SWIFT_LIBS}/${platform}")
set(SWIFT_INSTALL_RPATH "$ORIGIN/swift/${platform}")
Copy link
Member Author

Choose a reason for hiding this comment

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

As long as I'm modifying this line, I extended it to support more platforms and modified it to look in swift/os, not ../lib/swift/os. The former works fine for liblldb.so, whereas the latter is more general and can be used by lldb executables in bin/ too.

However, I checked and the only one it's added to is lldb-test, which the Swift toolchain doesn't ship. I can change this back to the more general ../lib/swift/os if wanted.

@finagolfin finagolfin changed the title [lldb][cmake] Remove local rpaths from the build host on ELF platforms [cmake] Remove local rpaths from the build host on ELF platforms Mar 13, 2023
@finagolfin
Copy link
Member Author

@augusto2112, please run the CI on this.

@augusto2112
Copy link

@swift-ci test

@finagolfin
Copy link
Member Author

finagolfin commented Mar 14, 2023

Alright, good sign that the CI passes, could someone build a toolchain for linux? I'll check its runpaths to make sure everything is okay.

@finagolfin
Copy link
Member Author

@bnbarham, mind triggering a CI build of the linux toolchain?

@augusto2112
Copy link

@swift-ci Please Build Toolchain Linux Platform

@bnbarham
Copy link

bnbarham commented Mar 14, 2023

@swift-ci please build toolchain Linux platform

EDIT: Apparently doesn't work in llvm-project. I've started over in swiftlang/swift#62616

@bnbarham
Copy link

@buttaface toolchain build succeeded - https://ci.swift.org/job/swift-PR-toolchain-Linux/386

@finagolfin
Copy link
Member Author

Downloaded it from swift.org and checked the rpaths, all good now and lldb works fine for checking a simple Swift executable.

Ready for review and merge, @bnbarham, would like to get this in before the branch.

@bnbarham bnbarham requested a review from JDevlieghere March 15, 2023 15:18
@finagolfin
Copy link
Member Author

@bnbarham, would you run the CI on this pull with swiftlang/swift-integration-tests#114 applied? That will make sure I got everything, maybe by running the CI from swiftlang/swift#62616 again if it can't be done from this repo.

@bnbarham
Copy link

Tests or toolchain again?

@finagolfin
Copy link
Member Author

Just the tests should be enough.

@bnbarham
Copy link

@finagolfin
Copy link
Member Author

@bnbarham, this repo doesn't run the integration tests, as I suspected, you will have to run these two pulls on that blank Swift repo pull again.

@finagolfin
Copy link
Member Author

Alright, this passed the linux CI on the linked Swift pull, and the new integration tests I added confirmed that all these incorrect local /home/build-user/ paths from the CI have been removed from the Swift toolchain with this pull.

This is ready for review and merge.

@JDevlieghere, since this pull is really fixing behavior that is only broken on this Swift fork, I'd like to get this in before the 5.9 branch, then we can go back and look at what should be upstreamed next week.

I definitely want to upstream removing that llvm_setup_rpath() invocation in compiler-rt, as it always sets the wrong runpaths there, and we can look into fixing llvm_setup_rpath() so it doesn't add these wrong directories for situations like this external lldb build.

However, I suspect that will take weeks to get that larger fix through the upstream review, and I'd like to get this smaller fix into the 5.9 branch before that.

@finagolfin
Copy link
Member Author

Ping @JDevlieghere and @bnbarham, what do you think about getting this in? It only fixes problems specific to this Swift fork, though elements of it can be spun off and used as part of a broader pull later to fix these rpath issues more generally upstream.

@JDevlieghere
Copy link

Ping @JDevlieghere and @bnbarham, what do you think about getting this in? It only fixes problems specific to this Swift fork, though elements of it can be spun off and used as part of a broader pull later to fix these rpath issues more generally upstream.

I guess I still don't understand in what way the issue is Swift-specific. I'm very wary when it comes to changing RPATHs, this is something that has backfired many times, both on macOS and Linux. I would feel more comfortable with a targeted patch that changes the RPATH for a particular library that needs it, rather than changing a high-level setting (LLDB_NO_INSTALL_DEFAULT_RPATH) and patching up seemingly unrelated tools like the driver.

@finagolfin
Copy link
Member Author

Let me break this down one by one:

I guess I still don't understand in what way the issue is Swift-specific.

This rpath issue only happens when one of these LLVM sub-projects is built separately. Since only this Swift toolchain builds lldb separately all the time and most non-Swift projects build all the LLVM sub-projects together, this primarily affects this Swift fork and not upstream LLVM.

I'm very wary when it comes to changing RPATHs, this is something that has backfired many times, both on macOS and Linux.

This pull only affects lldb on linux, it doesn't touch it on macOS. The compiler-rt libraries have their rpaths removed on all platforms, but only after checking to make sure the currently added rpaths are all wrong for those libraries.

I would feel more comfortable with a targeted patch that changes the RPATH for a particular library that needs it, rather than changing a high-level setting (LLDB_NO_INSTALL_DEFAULT_RPATH) and patching up seemingly unrelated tools like the driver.

LLDB_NO_INSTALL_DEFAULT_RPATH is the appropriate tool to disable calling llvm_setup_rpath() for the lldb sub-project, which adds a relative rpath and an incorrect absolute path to four separate lldb binaries listed in my top post and provides no other way to remove the absolute path. As pointed out before, LLDB_NO_INSTALL_DEFAULT_RPATH has already been set for macOS for many years. However, lldb on linux is the only one that still needs a relative rpath, so I add it back manually.

I'm not sure how you can say the lldb driver is "seemingly unrelated" to LLDB_NO_INSTALL_DEFAULT_RPATH, they both have lldb in the name.

I think we've shown with the passing CI runs and the successful CI toolchain build, which I then tested locally, that these changes don't break anything. I have submitted many pulls before removing and adjusting rpaths for the Swift toolchain and so far nothing has broken. I have some history with getting this right.

@JDevlieghere
Copy link

Let me break this down one by one:

I guess I still don't understand in what way the issue is Swift-specific.

This rpath issue only happens when one of these LLVM sub-projects is built separately. Since only this Swift toolchain builds lldb separately all the time and most non-Swift projects build all the LLVM sub-projects together, this primarily affects this Swift fork and not upstream LLVM.

The standalone build has always been a supported configuration for upstream LLDB. We have a dedicated bot for it. Recently there has been an RFC to formalize that across LLVM subprojects. This configuration doesn't exist strictly for Swift so saying that this is Swift specific is a stretch.

I'm very wary when it comes to changing RPATHs, this is something that has backfired many times, both on macOS and Linux.

This pull only affects lldb on linux, it doesn't touch it on macOS. The compiler-rt libraries have their rpaths removed on all platforms, but only after checking to make sure the currently added rpaths are all wrong for those libraries.

That doesn't really address my concern, Linux is a supported configuration, both upstream and downstream.

I would feel more comfortable with a targeted patch that changes the RPATH for a particular library that needs it, rather than changing a high-level setting (LLDB_NO_INSTALL_DEFAULT_RPATH) and patching up seemingly unrelated tools like the driver.

LLDB_NO_INSTALL_DEFAULT_RPATH is the appropriate tool to disable calling llvm_setup_rpath() for the lldb sub-project, which adds a relative rpath and an incorrect absolute path to four separate lldb binaries listed in my top post and provides no other way to remove the absolute path. As pointed out before, LLDB_NO_INSTALL_DEFAULT_RPATH has already been set for macOS for many years. However, lldb on linux is the only one that still needs a relative rpath, so I add it back manually.

Thanks for explaining this part. That wasn't clear to me from the PR description or the commit message. I would definitely recommend including that in the latter.

Anyway if that's the case (and I trust you when you say that it is) then that should just go upstream as I suggested earlier. I'm not an expert on the Linux configuration but there are upstream contributors that are and care about the standalone build. Those folks are better suited to review this and think of any potential fallout that might not affect the Swift fork. If they think it's fine, I have no issue with cherrypicking this to the Swift release branch.

I'm not sure how you can say the lldb driver is "seemingly unrelated" to LLDB_NO_INSTALL_DEFAULT_RPATH, they both have lldb in the name.

I think we've shown with the passing CI runs and the successful CI toolchain build, which I then tested locally, that these changes don't break anything.

I'm not so much worried about these changes breaking anything as the divergence with upstream.

I have submitted many pulls before removing and adjusting rpaths for the Swift toolchain and so far nothing has broken. I have some history with getting this right.

While I appreciate your contributions, I'm not sure what it adds to this (technical) discussion.

@finagolfin
Copy link
Member Author

Anyway if that's the case (and I trust you when you say that it is) then that should just go upstream as I suggested earlier. I'm not an expert on the Linux configuration but there are upstream contributors that are and care about the standalone build. Those folks are better suited to review this and think of any potential fallout that might not affect the Swift fork. If they think it's fine, I have no issue with cherrypicking this to the Swift release branch.

Understood, now that 5.9 has branched, we can take our time and get some of this in upstream first, since that is what you prefer.

@finagolfin
Copy link
Member Author

finagolfin commented Mar 29, 2023

I looked into this bootstrapping logic just now and it's a bit off for linux. The bootstrapping modes matter for macOS, but shouldn't for linux, as it doesn't check the bootstrapping mode anyway.

It happens to work right now because of this line setting a bootstrapping mode if there isn't one and SWIFT_SWIFT_PARSER is set, which won't work if --skip-early-swiftsyntax is passed into the build because it has to find the swift syntax source directory to set SWIFT_SWIFT_PARSER. I just checked the linux CI build log and SWIFT_SWIFT_PARSER is not set for lldb, so this won't work when there's no BOOTSTRAPPING_MODE. In fact, I'm not sure how it works on the linux CI at all, as no BOOTSTRAPPING_MODE is passed in when building lldb, even on macOS, yet somehow these rpaths are set for linux.

Should I modify thatlook further into this bootstrapping stuff too in this file or leave it alone for now?

@eeckstein
Copy link

regarding CI: you can check in the log which bootstrapping mode was used. It's printed when cmake is configuring, e.g.

-- Building host Swift tools for LINUX x86_64
--   Build type:     Release
--   Assertions:     TRUE
--   LTO:            
--   Bootstrapping:  BOOTSTRAPPING
--   Swift parser:   

@eeckstein
Copy link

So I think for linux it's fine, because CI is already testing the BOOTSTRAPPING mode.

@finagolfin
Copy link
Member Author

@eeckstein, that is the log output when building the compiler, this lldb build is wholly separate. This is the relevant lldb CMake config I was looking at, where there's no BOOTSTRAPPING_MODE set:

env /home/build-user/build/cmake-linux-x86_64/bin/cmake -G Ninja -DCMAKE_C_COMPILER:PATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:PATH=/usr/bin/clang++ -DCMAKE_Swift_COMPILER:PATH= -DCMAKE_LIBTOOL:PATH= -DCMAKE_AR:PATH=/usr/bin/ar -DCMAKE_RANLIB:PATH=/usr/bin/ranlib -DLLVM_VERSION_MAJOR:STRING=13 -DLLVM_VERSION_MINOR:STRING=0 -DLLVM_VERSION_PATCH:STRING=0 -DCLANG_VERSION_MAJOR:STRING=13 -DCLANG_VERSION_MINOR:STRING=0 -DCLANG_VERSION_PATCH:STRING=0 -DCMAKE_MAKE_PROGRAM=/home/build-user/build/buildbot_linux/ninja-build/ninja '-DLLVM_LIT_ARGS=-v --time-tests -j 36' -DSWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR:PATH=/home/build-user/build/buildbot_linux/earlyswiftsyntax-linux-x86_64 -C/home/build-user/llvm-project/lldb/cmake/caches/Apple-lldb-Linux.cmake '-DCMAKE_C_FLAGS=  -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector' '-DCMAKE_CXX_FLAGS=  -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector' -DCMAKE_BUILD_TYPE:STRING=Release -DLLDB_SWIFTC:PATH=/home/build-user/build/buildbot_linux/swift-linux-x86_64/bin/swiftc -DLLDB_SWIFT_LIBS:PATH=/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift -DCMAKE_INSTALL_PREFIX:PATH=/usr/ -DLLDB_FRAMEWORK_INSTALL_DIR=/usr/../System/Library/PrivateFrameworks -DLLVM_DIR:PATH=/home/build-user/build/buildbot_linux/llvm-linux-x86_64/lib/cmake/llvm -DClang_DIR:PATH=/home/build-user/build/buildbot_linux/llvm-linux-x86_64/lib/cmake/clang -DSwift_DIR:PATH=/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/cmake/swift -DLLDB_ENABLE_CURSES=ON -DLLDB_ENABLE_LIBEDIT=ON -DLLDB_ENABLE_PYTHON=ON -DLLDB_ENABLE_LZMA=OFF -DLLDB_ENABLE_LUA=OFF -DLLDB_INCLUDE_TESTS:BOOL=TRUE '-DLLDB_TEST_USER_ARGS=--build-dir;/home/build-user/build/buildbot_linux/lldb-linux-x86_64/lldb-test-build.noindex;--skip-category=watchpoint;--skip-category=dwo;-E;-I/home/build-user/build/buildbot_linux/foundation-linux-x86_64 -Xcc -F/home/build-user/build/buildbot_linux/foundation-linux-x86_64 -I/home/build-user/build/buildbot_linux/foundation-linux-x86_64/swift -I/home/build-user/swift-corelibs-libdispatch -L/home/build-user/build/buildbot_linux/libdispatch-linux-x86_64 -L/home/build-user/build/buildbot_linux/libdispatch-linux-x86_64/src -L/home/build-user/build/buildbot_linux/foundation-linux-x86_64 -L/home/build-user/build/buildbot_linux/foundation-linux-x86_64/Foundation -L/home/build-user/build/buildbot_linux/foundation-linux-x86_64/Sources/Foundation -L/home/build-user/build/buildbot_linux/foundation-linux-x86_64/Sources/FoundationNetworking -L/home/build-user/build/buildbot_linux/foundation-linux-x86_64/Sources/FoundationXML -L/home/build-user/build/buildbot_linux/foundation-linux-x86_64/lib -Xlinker -rpath -Xlinker /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64 -Xlinker -rpath -Xlinker /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64/src -Xlinker -rpath -Xlinker /home/build-user/build/buildbot_linux/foundation-linux-x86_64 -Xlinker -rpath -Xlinker /home/build-user/build/buildbot_linux/foundation-linux-x86_64/Foundation -Xlinker -rpath -Xlinker /home/build-user/build/buildbot_linux/foundation-linux-x86_64/Sources/Foundation -Xlinker -rpath -Xlinker /home/build-user/build/buildbot_linux/foundation-linux-x86_64/Sources/FoundationNetworking -Xlinker -rpath -Xlinker /home/build-user/build/buildbot_linux/foundation-linux-x86_64/Sources/FoundationXML -Xlinker -rpath -Xlinker /home/build-user/build/buildbot_linux/foundation-linux-x86_64/lib' -USWIFT_DARWIN_SUPPORTED_ARCHS -DSWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE:PATH=/home/build-user/swift-syntax /home/build-user/llvm-project/lldb

However, looking at that giant list closely now, I just noticed this, -DSwift_DIR:PATH=/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/cmake/swift, so my guess is that it's picking up the bootstrapping mode from those generated CMake config files for the Swift compiler. Anyway, it works for now, we can revisit that bootstrapping setup later.

Please approve if you're okay with the rpath updates for linux in this pull.

@finagolfin
Copy link
Member Author

@bnbarham, one last CI run and we can get this in.

@bnbarham
Copy link

@finagolfin
Copy link
Member Author

@bnbarham, this CI won't run integration tests. Anyway, no need to run that, as it will depend on getting my upstream LLVM patch in first.

@bnbarham
Copy link

@bnbarham, this CI won't run integration tests. Anyway, no need to run that, as it will depend on getting my upstream LLVM patch in first.

I was just copying what I ran above :). If it doesn't run them it shouldn't matter.

@finagolfin
Copy link
Member Author

Huh, now it's failing the lldb tests on linux, strange, since the larger version of this pull passed them before. I'll look into it.

@finagolfin
Copy link
Member Author

Built this locally and spent some time looking into it: the issue appears to be that this build rpath I'm splitting off isn't applied because BUILD_WITH_INSTALL_RPATH is still set in llvm_setup_rpath(). It looks like that overrides all build rpaths and only applies install rpaths, both when building and installing.

Since the LLVM patch I submitted upstream removes that CMake flag for ELF platforms, this pull depends on that patch going in first. Once that's in, this should work again.

@finagolfin
Copy link
Member Author

finagolfin commented Apr 20, 2023

Upstream patch was just merged, so I cherry-picked it here to this stable branch and rebased.

@bnbarham, if you would kick off another CI run here, let's see if this works now.

@bnbarham
Copy link

@swift-ci please test

@finagolfin
Copy link
Member Author

Alright, linux CI passed now and single test failing on mac CI, something related to a tsan race, appears spurious: this is ready to go in.

Butta and others added 3 commits April 22, 2023 01:48
… in llvm_setup_rpath()

If any LLVM subprojects are built separately, the LLVM build directory
LLVM_LIBRARY_DIR is added to both the build and install runpaths in
llvm_setup_rpath(), which is incorrect when installed. Separate the
build and install runpaths on ELF platforms and finally remove the
incorrect call to this function for compiler-rt, as previously attempted
in 21c008d. That prior attempt was reverted in 959dbd1, where it
was said to break the build on macOS and Windows, so I made sure to keep
those platforms the same.

Two examples of incorrect runpaths that are currently added, one from
the latest LLVM 16 toolchain for linux x86_64:

  > readelf -d clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.*so | ag "File:|runpath"
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.asan.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.dyndd.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan_aliases.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.hwasan.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.memprof.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.scudo_standalone.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.tsan.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_minimal.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]
  File: clang+llvm-16.0.0-x86_64-linux-gnu-ubuntu-18.04/lib/clang/16/lib/x86_64-unknown-linux-gnu/libclang_rt.ubsan_standalone.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/tmp/llvm_release/final/Phase3/Release/llvmCore-16.0.0-final.obj/./lib]

Another is in the Swift toolchain, which builds lldb separately:

  > readelf -d swift-5.9-DEVELOPMENT-SNAPSHOT-2023-03-24-a-ubuntu20.04/usr/{bin/lldb*,lib/liblldb.so}|ag "File:|runpath"
  File: swift-5.9-DEVELOPMENT-SNAPSHOT-2023-03-24-a-ubuntu20.04/usr/bin/lldb
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib]
  File: swift-5.9-DEVELOPMENT-SNAPSHOT-2023-03-24-a-ubuntu20.04/usr/bin/lldb-argdumper
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib]
  File: swift-5.9-DEVELOPMENT-SNAPSHOT-2023-03-24-a-ubuntu20.04/usr/bin/lldb-server
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib]
  File: swift-5.9-DEVELOPMENT-SNAPSHOT-2023-03-24-a-ubuntu20.04/usr/lib/liblldb.so
  0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/home/build-user/build/buildbot_linux/llvm-linux-x86_64/./lib:/home/build-user/build/buildbot_linux/swift-linux-x86_64/lib/swift/linux:$ORIGIN/../lib/swift/linux]

This patch should fix this problem of absolute paths from the build host
leaking out into the toolchain's runpaths.

Differential revision: https://reviews.llvm.org/D146918
Recent commit llvm@8f833f8 modified the installation rpath and did not set `BUILD_WITH_INSTALL_RPATH` correctly on AIX, which led to installation failures on AIX. This patch sets `BUILD_WITH_INSTALL_RPATH` on AIX to fix the installation failures.

Reviewed By: buttaface, daltenty

Differential Revision: https://reviews.llvm.org/D148866
Also, add rpath support for more platforms, like Android and the BSDs.
@finagolfin
Copy link
Member Author

Another AIX/Windows change to this CMake method was merged upstream, so I cherry-picked that commit too and rebased.

One last CI run and we can get this in.

finagolfin added a commit to finagolfin/swift-integration-tests that referenced this pull request Apr 23, 2023
…a /home runpath from the build host again

Also, update the liblldb.so runpath for swiftlang/llvm-project#6456.
@finagolfin
Copy link
Member Author

@bnbarham, please run the CI on the main compiler repo with this pull and swiftlang/swift-integration-tests#114, which I recently updated for this pull, and we can make sure these runpath changes are working well.

@finagolfin
Copy link
Member Author

Alright, this passed CI along with the integration test. Both were approved and the only changes I made after that is to add the upstream commits here and modified the integration test for the new liblldb.so runpath in my last commit here.

Since this is all passing the CI, would you merge this pull and swiftlang/swift-integration-tests#114 together now, @bnbarham? They have to be merged around the same time, as the integration test depends on this pull.

@bnbarham
Copy link

bnbarham commented May 1, 2023

@swift-ci please test

@finagolfin
Copy link
Member Author

Passed all CI, ready for merge.

@finagolfin
Copy link
Member Author

Ping @bnbarham, this one and the integration test can be merged, will submit this for 5.9 next.

@bnbarham bnbarham merged commit 951f936 into swiftlang:stable/20221013 May 4, 2023
@finagolfin finagolfin deleted the rpath branch May 5, 2023 05:16
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.

5 participants