* [PATCH v2] configure: Improve alias attribute check
@ 2021-03-21 0:17 Gavin Shan
2021-03-21 13:37 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Gavin Shan @ 2021-03-21 0:17 UTC (permalink / raw)
To: qemu-devel
Cc: thuth, richard.henderson, laurent, qemu-arm, shan.gavin,
pbonzini, philmd
It's still possible that the wrong value is returned from the alias
of variable even if the program can be compiled without issue. This
improves the check by executing the binary to check the result.
If alias attribute can't be working properly, the @target_page in
exec-vary.c will always return zeroes when we have the following gcc
version and the combination of options "-O2 -flto=auto".
# gcc --version
gcc (GCC) 11.0.0 20210210 (Red Hat 11.0.0-0)
This abstracts the code from exec-vary.c and use it as indicator to
enable gcc alias attribute or not. The gcc alias attribute is disabled
for the cross-compiling case as the compiled binary isn't executable.
Signed-off-by: Gavin Shan <gshan@redhat.com>
---
v2: Disable gcc alias attribute for cross-compiling case.
Return 0 on success from test program.
Wrap lines of test program and improved commit log.
---
configure | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/configure b/configure
index f7d022a5db..77d7110e5c 100755
--- a/configure
+++ b/configure
@@ -75,6 +75,7 @@ fi
TMPB="qemu-conf"
TMPC="${TMPDIR1}/${TMPB}.c"
+TMPC_B="${TMPDIR1}/${TMPB}_b.c"
TMPO="${TMPDIR1}/${TMPB}.o"
TMPCXX="${TMPDIR1}/${TMPB}.cxx"
TMPE="${TMPDIR1}/${TMPB}.exe"
@@ -4878,13 +4879,27 @@ fi
attralias=no
cat > $TMPC << EOF
-int x = 1;
+static int x;
extern const int y __attribute__((alias("x")));
-int main(void) { return 0; }
+extern int read_y(void);
+void write_x(int val);
+
+void write_x(int val) { x = val; }
+int main(void) { return (read_y() == 1) ? 0 : 1; }
EOF
-if compile_prog "" "" ; then
- attralias=yes
+cat > $TMPC_B << EOF
+extern const int y;
+extern void write_x(int val);
+int read_y(void);
+
+int read_y(void) { write_x(1); return y;}
+EOF
+
+TMPC+=" ${TMPC_B}"
+if compile_prog "" "" && $TMPE >/dev/null 2>/dev/null; then
+ attralias=yes
fi
+TMPC="${TMPDIR1}/${TMPB}.c"
########################################
# check if getauxval is available.
--
2.23.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] configure: Improve alias attribute check
2021-03-21 0:17 [PATCH v2] configure: Improve alias attribute check Gavin Shan
@ 2021-03-21 13:37 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-03-21 13:37 UTC (permalink / raw)
To: Gavin Shan, qemu-devel
Cc: thuth, richard.henderson, laurent, qemu-arm, shan.gavin, philmd
On 21/03/21 01:17, Gavin Shan wrote:
> It's still possible that the wrong value is returned from the alias
> of variable even if the program can be compiled without issue. This
> improves the check by executing the binary to check the result.
>
> If alias attribute can't be working properly, the @target_page in
> exec-vary.c will always return zeroes when we have the following gcc
> version and the combination of options "-O2 -flto=auto".
>
> # gcc --version
> gcc (GCC) 11.0.0 20210210 (Red Hat 11.0.0-0)
>
> This abstracts the code from exec-vary.c and use it as indicator to
> enable gcc alias attribute or not. The gcc alias attribute is disabled
> for the cross-compiling case as the compiled binary isn't executable.
>
> Signed-off-by: Gavin Shan <gshan@redhat.com>
NACK, let's first try to figure out a way to preserve the optimization
without using aliases.
Paolo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-21 13:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 0:17 [PATCH v2] configure: Improve alias attribute check Gavin Shan
2021-03-21 13:37 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.