Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ extension GenericUnixToolchain {
commandLine.appendPath(toolsDir)
}

// Executables on Linux get -pie
// Executables on Linux get -fpie
if targetTriple.os == .linux && linkerOutputType == .executable {
commandLine.appendFlag("-pie")
commandLine.appendFlag("-fpie")
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused by this change. The spelling is -pie for the linker driver invocation, but -fpie for the compiler invocation (unless you are on certain platforms, where the spelling is -fPIE) under certain circumstances.

-pie is the equivalent of -shared but for executables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clearing that up, I had confused the two. @cachemeifyoucan pointed out that the warning we get appears to be due to the Clang driver emitting it for platforms where the toolchain default for executables is PIE.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am actually unsure where the warning coming from before seeing the build log. I suggest it is better if you just pass -Xlinker -pie if you worried about unused argument warning.

}

// On some platforms we want to enable --build-id
Expand Down
10 changes: 10 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2069,6 +2069,16 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertTrue(cmd.contains(subsequence: [.flag("-Xlinker"), .flag("-rpath=$ORIGIN"), .flag("foo")]))
}

do {
// Ensure executables get '-fpie'
var driver = try Driver(args: commonArgs + ["-emit-executable", "-L", "/tmp", "-target", "x86_64-unknown-linux"], env: env)
let plannedJobs = try driver.planBuild()
XCTAssertEqual(plannedJobs.count, 4)
let linkJob = plannedJobs[3]
let cmd = linkJob.commandLine
XCTAssertTrue(cmd.contains(subsequence: [.flag("-fpie")]))
}

do {
// Xlinker flags
// Ensure that Xlinker flags are passed as such to the clang linker invocation.
Expand Down