Skip to content

Commit 2257667

Browse files
authored
Merge pull request swiftlang#30864 from drexin/wip-fix-static-executable
Fix linker flags for -static-executable
2 parents 1b26b96 + e4e6c16 commit 2257667

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

lib/Driver/UnixToolChains.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
211211
Arguments.push_back(context.Args.MakeArgString(A->getValue()));
212212
}
213213

214-
if (getTriple().getOS() == llvm::Triple::Linux &&
215-
job.getKind() == LinkKind::Executable) {
214+
if (getTriple().getObjectFormat() == llvm::Triple::ELF &&
215+
job.getKind() == LinkKind::Executable &&
216+
!context.Args.hasFlag(options::OPT_static_executable,
217+
options::OPT_no_static_executable, false)) {
216218
Arguments.push_back("-pie");
217219
}
218220

test/Driver/static-executable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Create a self contained binary
2+
// REQUIRES: OS=linux-gnu
3+
// REQUIRES: static_stdlib
4+
print("hello world!")
5+
// RUN: %empty-directory(%t)
6+
// RUN: %target-swiftc_driver -static-executable -o %t/static-executable %s
7+
// RUN: %t/static-executable | %FileCheck %s
8+
// RUN: %llvm-readelf -program-headers %t/static-executable | %FileCheck %s --check-prefix=ELF
9+
// CHECK: hello world!
10+
// ELF-NOT: INTERP

test/lit.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ config.llvm_cov = inferSwiftBinary('llvm-cov')
288288
config.llvm_strings = inferSwiftBinary('llvm-strings')
289289
config.filecheck = inferSwiftBinary('FileCheck')
290290
config.llvm_dwarfdump = inferSwiftBinary('llvm-dwarfdump')
291+
config.llvm_readelf = inferSwiftBinary('llvm-readelf')
291292
config.llvm_dis = inferSwiftBinary('llvm-dis')
292293
config.sourcekitd_test = inferSwiftBinary('sourcekitd-test')
293294
config.complete_test = inferSwiftBinary('complete-test')
@@ -434,6 +435,7 @@ config.substitutions.append( ('%swift-indent', config.swift_indent) )
434435
config.substitutions.append( ('%llvm-link', config.llvm_link) )
435436
config.substitutions.append( ('%swift-llvm-opt', config.swift_llvm_opt) )
436437
config.substitutions.append( ('%llvm-dwarfdump', config.llvm_dwarfdump) )
438+
config.substitutions.append( ('%llvm-readelf', config.llvm_readelf) )
437439
config.substitutions.append( ('%llvm-dis', config.llvm_dis) )
438440
config.substitutions.append( ('%swift-demangle-yamldump', config.swift_demangle_yamldump) )
439441
config.substitutions.append( ('%Benchmark_O', config.benchmark_o) )

utils/static-executable-args.lnk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
-Xlinker
99
--defsym=__import_pthread_key_create=pthread_key_create
1010
-lpthread
11-
-licui18n
12-
-licuuc
13-
-licudata
11+
-licui18nswift
12+
-licuucswift
13+
-licudataswift
1414
-ldl
1515
-lstdc++
1616
-lm

0 commit comments

Comments
 (0)