Skip to content

Commit b03fcd6

Browse files
committed
meson: move -no-pie from linker to compiler
The large comment in the patch says it all; the -no-pie flag is broken and this is why it was not included in QEMU_LDFLAGS before commit a988b4c ("build: move remaining compiler flag tests to meson", 2023-05-18). And some distros made things even worse, so we have to add it to the compiler command line. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1664 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 91a2e68 commit b03fcd6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

meson.build

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,21 @@ endif
265265

266266
# Meson currently only handles pie as a boolean for now, so if the user
267267
# has explicitly disabled PIE we need to extend our cflags.
268+
#
269+
# -no-pie is supposedly a linker flag that has no effect on the compiler
270+
# command line, but some distros, that didn't quite know what they were
271+
# doing, made local changes to gcc's specs file that turned it into
272+
# a compiler command-line flag.
273+
#
274+
# What about linker flags? For a static build, no PIE is implied by -static
275+
# which we added above (and if it's not because of the same specs patching,
276+
# there's nothing we can do: compilation will fail, report a bug to your
277+
# distro and do not use --disable-pie in the meanwhile). For dynamic linking,
278+
# instead, we can't add -no-pie because it overrides -shared: the linker then
279+
# tries to build an executable instead of a shared library and fails. So
280+
# don't add -no-pie anywhere and cross fingers. :(
268281
if not get_option('b_pie')
269-
qemu_common_flags += cc.get_supported_arguments('-fno-pie')
270-
if not get_option('prefer_static')
271-
# No PIE is implied by -static which we added above.
272-
qemu_ldflags += cc.get_supported_link_arguments('-no-pie')
273-
endif
282+
qemu_common_flags += cc.get_supported_arguments('-fno-pie', '-no-pie')
274283
endif
275284

276285
if not get_option('stack_protector').disabled()

0 commit comments

Comments
 (0)