[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug gas/16858] weak external reference has wrong value
From: |
mikpelinux at gmail dot com |
Subject: |
[Bug gas/16858] weak external reference has wrong value |
Date: |
Mon, 21 Apr 2014 20:39:02 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=16858
Mikael Pettersson <mikpelinux at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mikpelinux at gmail dot com
--- Comment #3 from Mikael Pettersson <mikpelinux at gmail dot com> ---
I can reproduce the crash on cygwin-1.7.29 (32-bit), with binutils 2.21,
2.21.1, 2.23.2, and cygwin's 2.24.51.20140326.
Modifying test.c to optionally move the test() definition before main(), .e.g:
> cat test.c
#include <stdio.h>
#ifdef REORDER
__attribute__((weak))
void test()
{
printf("weak\n");
}
#else
extern void test() __attribute__((weak));
#endif
int main()
{
printf("hello\n");
test();
return 0;
}
#ifndef REORDER
__attribute__((weak))
void test()
{
printf("weak\n");
}
#endif
illustrates that the bug is ordering-dependent:
> gcc -UREORDER -g test.c test1.c ; ./a.exe
hello
Segmentation fault (core dumped)
> gcc -DREORDER -g test.c test1.c ; ./a.exe
hello
strong
An objdump -d -r of the broken a.exe shows that what should have been a call to
the strong test() in fact calls an immediate field in main() itself:
00401190 <_main>:
401190: 55 push %ebp
401191: 89 e5 mov %esp,%ebp
401193: 83 e4 f0 and $0xfffffff0,%esp
401196: 83 ec 10 sub $0x10,%esp
401199: e8 b2 00 00 00 call 401250 <___main>
40119e: c7 04 24 60 30 40 00 movl $0x403060,(%esp)
4011a5: e8 ae 00 00 00 call 401258 <_puts>
4011aa: e8 f7 ff ff ff call 4011a6 <_main+0x16>
4011af: b8 00 00 00 00 mov $0x0,%eax
4011b4: c9 leave
4011b5: c3 ret
The insn at 0x4011aa should have called test() [at 0x4011cc in this exe], but
instead calls the immediate in the preceding _puts call.
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug gas/16858] New: weak external, bernd.edlinger at hotmail dot de, 2014/04/21
- [Bug gas/16858] weak external, bernd.edlinger at hotmail dot de, 2014/04/21
- [Bug gas/16858] weak external reference has wrong value, bernd.edlinger at hotmail dot de, 2014/04/21
- [Bug gas/16858] weak external reference has wrong value, bernd.edlinger at hotmail dot de, 2014/04/21
- [Bug gas/16858] weak external reference has wrong value, address@hidden, 2014/04/21
- [Bug gas/16858] weak external reference has wrong value,
mikpelinux at gmail dot com <=
- [Bug gas/16858] weak external reference has wrong value, mikpelinux at gmail dot com, 2014/04/23
- [Bug gas/16858] weak external reference has wrong value, nickc at redhat dot com, 2014/04/25
- [Bug gas/16858] weak external reference has wrong value, nickc at redhat dot com, 2014/04/25
- [Bug gas/16858] weak external reference has wrong value, mikpelinux at gmail dot com, 2014/04/27
- [Bug gas/16858] weak external reference has wrong value, cvs-commit at gcc dot gnu.org, 2014/04/28
- [Bug gas/16858] weak external reference has wrong value, nickc at redhat dot com, 2014/04/28
- [Bug gas/16858] weak external reference has wrong value, bernd.edlinger at hotmail dot de, 2014/04/29