* [PATCH v2] meson: move -no-pie from linker to compiler
@ 2023-05-23 7:30 Paolo Bonzini
2023-05-23 8:16 ` Philippe Mathieu-Daudé
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Paolo Bonzini @ 2023-05-23 7:30 UTC (permalink / raw)
To: qemu-devel; +Cc: marcandre.lureau, vr_qemu, richard.henderson
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 a988b4c5614
("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>
---
meson.build | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/meson.build b/meson.build
index 0a5cdefd4d3d..20accae99281 100644
--- a/meson.build
+++ b/meson.build
@@ -265,12 +265,21 @@ endif
# Meson currently only handles pie as a boolean for now, so if the user
# has explicitly disabled PIE we need to extend our cflags.
+#
+# -no-pie is supposedly a linker flag that has no effect on the compiler
+# command line, but some distros, that didn't quite know what they were
+# doing, made local changes to gcc's specs file that turned it into
+# a compiler command-line flag.
+#
+# What about linker flags? For a static build, no PIE is implied by -static
+# which we added above (and if it's not because of the same specs patching,
+# there's nothing we can do: compilation will fail, report a bug to your
+# distro and do not use --disable-pie in the meanwhile). For dynamic linking,
+# instead, we can't add -no-pie because it overrides -shared: the linker then
+# tries to build an executable instead of a shared library and fails. So
+# don't add -no-pie anywhere and cross fingers. :(
if not get_option('b_pie')
- qemu_common_flags += cc.get_supported_arguments('-fno-pie')
- if not get_option('prefer_static')
- # No PIE is implied by -static which we added above.
- qemu_ldflags += cc.get_supported_link_arguments('-no-pie')
- endif
+ qemu_common_flags += cc.get_supported_arguments('-fno-pie', '-no-pie')
endif
if not get_option('stack_protector').disabled()
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] meson: move -no-pie from linker to compiler
2023-05-23 7:30 [PATCH v2] meson: move -no-pie from linker to compiler Paolo Bonzini
@ 2023-05-23 8:16 ` Philippe Mathieu-Daudé
2023-05-23 14:08 ` Richard Henderson
2023-05-24 6:04 ` Volker Rümelin
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-05-23 8:16 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: marcandre.lureau, vr_qemu, richard.henderson
On 23/5/23 09:30, Paolo Bonzini wrote:
> 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 a988b4c5614
> ("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>
> ---
> meson.build | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/meson.build b/meson.build
> index 0a5cdefd4d3d..20accae99281 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -265,12 +265,21 @@ endif
>
> # Meson currently only handles pie as a boolean for now, so if the user
> # has explicitly disabled PIE we need to extend our cflags.
> +#
> +# -no-pie is supposedly a linker flag that has no effect on the compiler
> +# command line, but some distros, that didn't quite know what they were
> +# doing, made local changes to gcc's specs file that turned it into
> +# a compiler command-line flag.
> +#
> +# What about linker flags? For a static build, no PIE is implied by -static
> +# which we added above (and if it's not because of the same specs patching,
> +# there's nothing we can do: compilation will fail, report a bug to your
> +# distro and do not use --disable-pie in the meanwhile). For dynamic linking,
> +# instead, we can't add -no-pie because it overrides -shared: the linker then
> +# tries to build an executable instead of a shared library and fails. So
> +# don't add -no-pie anywhere and cross fingers. :(
> if not get_option('b_pie')
> - qemu_common_flags += cc.get_supported_arguments('-fno-pie')
> - if not get_option('prefer_static')
> - # No PIE is implied by -static which we added above.
> - qemu_ldflags += cc.get_supported_link_arguments('-no-pie')
> - endif
> + qemu_common_flags += cc.get_supported_arguments('-fno-pie', '-no-pie')
> endif
This removes this annoying warning with Clang on Darwin/Aarch64:
clang: warning: argument unused during compilation: '-no-pie'
[-Wunused-command-line-argument]
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] meson: move -no-pie from linker to compiler
2023-05-23 7:30 [PATCH v2] meson: move -no-pie from linker to compiler Paolo Bonzini
2023-05-23 8:16 ` Philippe Mathieu-Daudé
@ 2023-05-23 14:08 ` Richard Henderson
2023-05-24 6:04 ` Volker Rümelin
2 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2023-05-23 14:08 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: marcandre.lureau, vr_qemu
On 5/23/23 00:30, Paolo Bonzini wrote:
> 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 a988b4c5614
> ("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>
> ---
> meson.build | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] meson: move -no-pie from linker to compiler
2023-05-23 7:30 [PATCH v2] meson: move -no-pie from linker to compiler Paolo Bonzini
2023-05-23 8:16 ` Philippe Mathieu-Daudé
2023-05-23 14:08 ` Richard Henderson
@ 2023-05-24 6:04 ` Volker Rümelin
2 siblings, 0 replies; 4+ messages in thread
From: Volker Rümelin @ 2023-05-24 6:04 UTC (permalink / raw)
To: Paolo Bonzini, qemu-devel; +Cc: marcandre.lureau, richard.henderson
Am 23.05.23 um 09:30 schrieb Paolo Bonzini:
> 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 a988b4c5614
> ("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>
> ---
> meson.build | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/meson.build b/meson.build
> index 0a5cdefd4d3d..20accae99281 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -265,12 +265,21 @@ endif
>
> # Meson currently only handles pie as a boolean for now, so if the user
> # has explicitly disabled PIE we need to extend our cflags.
> +#
> +# -no-pie is supposedly a linker flag that has no effect on the compiler
> +# command line, but some distros, that didn't quite know what they were
> +# doing, made local changes to gcc's specs file that turned it into
> +# a compiler command-line flag.
> +#
> +# What about linker flags? For a static build, no PIE is implied by -static
> +# which we added above (and if it's not because of the same specs patching,
> +# there's nothing we can do: compilation will fail, report a bug to your
> +# distro and do not use --disable-pie in the meanwhile). For dynamic linking,
> +# instead, we can't add -no-pie because it overrides -shared: the linker then
> +# tries to build an executable instead of a shared library and fails. So
> +# don't add -no-pie anywhere and cross fingers. :(
> if not get_option('b_pie')
> - qemu_common_flags += cc.get_supported_arguments('-fno-pie')
> - if not get_option('prefer_static')
> - # No PIE is implied by -static which we added above.
> - qemu_ldflags += cc.get_supported_link_arguments('-no-pie')
> - endif
> + qemu_common_flags += cc.get_supported_arguments('-fno-pie', '-no-pie')
> endif
>
> if not get_option('stack_protector').disabled()
I tested that QEMU builds on Windows with MSYS2 mingw64.
One unrelated note: The DLL loader doesn't find the libslirp-0.dll when
QEMU was built with libslirp from the subprojects folder and started
from the build folder. It's necessary to copy this library to a folder
in the DLL search path.
Tested-by: Volker Rümelin <vr_qemu@t-online.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-24 6:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-23 7:30 [PATCH v2] meson: move -no-pie from linker to compiler Paolo Bonzini
2023-05-23 8:16 ` Philippe Mathieu-Daudé
2023-05-23 14:08 ` Richard Henderson
2023-05-24 6:04 ` Volker Rümelin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).