meson: use -static-pie instead of -static in PIE mode

If compiling with -Db_pie=true, we should do PIE compilation (position
independent executables), even in the static mode.

The caveat is that people distributions actually override compilation
flags when doing their builds. They'll need to set the static flags
properly if they do such builds.

(cherry picked from commit 8b289a8c4d)
This commit is contained in:
Zbigniew Jędrzejewski-Szmek authored and Luca Boccassi committed 2026-10-16 11:36:33 +01:00
1 parent b7ae93f093
commit dfdcaaa269
2 files changed
+14 -4

No files matched your search

+2 -3
View File
@@ -1028,9 +1028,8 @@ libm = cc.find_library('m')
# On some architectures, libatomic is required. But on some installations,
# it is found, but actual linking fails. So let's try to use it opportunistically.
# If it is installed, but not needed, it will be dropped because of --as-needed.
if cc.links('''int main(int argc, char **argv) { return 0; }''',
args : '-latomic',
name : 'libatomic')
basic_c_prog = '''int main(int argc, char **argv) { return 0; }'''
if cc.links(basic_c_prog, args : '-latomic', name : 'libatomic')
libatomic = declare_dependency(link_args : '-latomic')
else
libatomic = []
+12 -1
View File
@@ -219,13 +219,24 @@ if conf.get('SYSTEMD_MULTICALL_BINARY') == 1
]
endif
if get_option('build-static')
if (get_option('b_pie') and
cc.links(basic_c_prog, args : '-static-pie', name : '-static-pie'))
systemd_link_args = ['-static-pie', '-Wl,-static,-pie']
else
systemd_link_args = ['-static']
endif
else
systemd_link_args = []
endif
executables += [
libexec_template + {
'name' : 'systemd',
'dbus' : true,
'public' : true,
'sources' : systemd_sources,
'link_args_static' : get_option('build-static') ? ['-static'] : [],
'link_args_static' : systemd_link_args,
'link_with' : [
libcore,
libshared,