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

Add -z,origin linker flag on OpenBSD. #5196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions Sources/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ set_target_properties(Foundation PROPERTIES
INSTALL_RPATH "$ORIGIN"
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)

if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_link_options(Foundation PRIVATE "LINKER:-z,origin")
Copy link
Contributor

Choose a reason for hiding this comment

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

All of the targets in the Foundation project (both those here as well as those in swift-foundation) use ORIGIN-based rpath values. Is there something special about the Foundation library, or should this be provided for all of these targets?

Copy link
Member

Choose a reason for hiding this comment

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

-z origin is a flag that is useful in the odd case that the reference to $ORIGIN does not occur in DT_NEEDED or DT_RUNPATH (DT_RPATH also applies, but that is considered deprecated) and is expected to possibly occur at runtime through libdl (i.e. dlopen). In such cases the computation may be elided as the value is unneeded and could cause a failure otherwise due to the missing value.

Copy link
Member Author

Choose a reason for hiding this comment

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

On OpenBSD, -z origin is also required to properly resolve $ORIGIN.

I'm fairly sure this will be required for the other targets, and only the main Foundation library has posed a problem while trying to get the toolchain stood up end to end, so I've only added it for Foundation so far.

It probably is the case I should add them for the other targets, but I need to double-check.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, right, this is Open, not Free. Open and DragonFly both need -z origin.

endif()

if(dispatch_FOUND)
set_target_properties(Foundation PROPERTIES
BUILD_RPATH "$<TARGET_FILE_DIR:swiftDispatch>")
Expand Down
4 changes: 4 additions & 0 deletions Sources/FoundationNetworking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ set_target_properties(FoundationNetworking PROPERTIES
INSTALL_RPATH "$ORIGIN"
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)

if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_link_options(Foundation PRIVATE "LINKER:-z,origin")
endif()

if(LINKER_SUPPORTS_BUILD_ID)
target_link_options(FoundationNetworking PRIVATE "LINKER:--build-id=sha1")
endif()
Expand Down
4 changes: 4 additions & 0 deletions Sources/FoundationXML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ set_target_properties(FoundationXML PROPERTIES
INSTALL_RPATH "$ORIGIN"
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)

if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_link_options(Foundation PRIVATE "LINKER:-z,origin")
endif()

if(LINKER_SUPPORTS_BUILD_ID)
target_link_options(FoundationXML PRIVATE "LINKER:--build-id=sha1")
endif()
Expand Down
4 changes: 4 additions & 0 deletions Sources/plutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ set_target_properties(plutil PROPERTIES
INSTALL_RPATH "$ORIGIN/../lib/swift/${SWIFT_SYSTEM_NAME}"
INSTALL_REMOVE_ENVIRONMENT_RPATH ON)

if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
target_link_options(Foundation PRIVATE "LINKER:-z,origin")
endif()

set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS plutil)
install(TARGETS plutil
DESTINATION ${CMAKE_INSTALL_BINDIR})