qemu-arm
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] configure: Improve alias attribute check


From: Gavin Shan
Subject: Re: [PATCH] configure: Improve alias attribute check
Date: Mon, 22 Mar 2021 21:54:36 +1100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0

Hi Richard and Paolo,

On 3/22/21 5:23 AM, Richard Henderson wrote:
On 3/21/21 11:46 AM, Paolo Bonzini wrote:
HRM, what about biting the bullet and making exec-vary.c a C++ source?... Then 
instead of making it conditional an attribute((alias)), we make it conditional 
on having a C++ compiler.

Doesn't help.  The gcc bug I filed talks about c++, because that's the closest 
analogy.

But set_preferred_target_page_bits is called *much* later than a constructor. 
Though still before any use of the variable in question, for which we have an 
--enable-debug-tcg assertion.


It looks this issue can be avoided after "volatile" is applied to
@target_page. However, I'm not sure if it's the correct fix to have.
If it is, I can post a formal patch so that it can be included.

--- a/exec-vary.c
+++ b/exec-vary.c
-extern const TargetPageBits target_page
+extern const TargetPageBits volatile target_page
     __attribute__((alias("init_target_page")));
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
-extern const TargetPageBits target_page;
+extern const TargetPageBits volatile target_page;


According to the experiments I did, it would be function call
to set_preferred_target_page_bits() is dropped when the machine
is created. The following c files are used in the experiment:

--- a.c ---

static int x;
const extern int VOLATILE y __attribute__((alias("x")));
extern int read_y(void);

void write_x(int val) { x = 1; }
int main(void) { return read_y(); }

--- b.c---

extern const int VOLATILE y;
extern void write_x(int val);

int read_y(void) { write_x(1); return y; }

# gcc a.c b.c -O2 -flto=auto -DVOLATILE= -o a; ./a; echo $?
0
# gdb -nw ./a
(gdb) disassem main
Dump of assembler code for function main:
   0x0000000000400480 <+0>:       adrp    x1, 0x420000 
<__libc_start_main@got.plt>
   0x0000000000400484 <+4>:       mov     w2, #0x1                        // #1
   0x0000000000400488 <+8>:       mov     w0, #0x0                        // #0
   0x000000000040048c <+12>:      str     w2, [x1, #32]
   0x0000000000400490 <+16>:      ret
End of assembler dump.

# gcc a.c b.c -O2 -flto=auto -DVOLATILE=volatile -o a; ./a; echo $?
1
# gdb -nw ./a
(gdb) disassem main
Dump of assembler code for function main:
   0x0000000000400480 <+0>:       adrp    x1, 0x420000 
<__libc_start_main@got.plt>
   0x0000000000400484 <+4>:       mov     w2, #0x1                        // #1
   0x0000000000400488 <+8>:       adrp    x0, 0x420000 
<__libc_start_main@got.plt>
   0x000000000040048c <+12>:      str     w2, [x1, #32]
   0x0000000000400490 <+16>:      ldr     w0, [x0, #32]
   0x0000000000400494 <+20>:      ret


Thanks,
Gavin




reply via email to

[Prev in Thread] Current Thread [Next in Thread]