Hello,
I found this one while playing with Cygwin's code which takes care of
seamless loading of dll functions (autoload.cc). It seems that when a
symbol in a section marked .linkonce is referenced, wrong relocation info
is generated for that symbol.
For example if you have several symbols - symbol1, symbol2 and symbol3,
- which are placed like this:
offset name
0 symbol1
3 symbol2
15 symbol3
References to this symbols will be generated like this:
symbol1 -> 0
symbol2 -> 6
symbol3 -> 30
I am attaching a testcase. linkonce.cc is the code which demonstrates the
problem. linkonce1.cc is the same code but with .linkonce directives
removed and doesn't suffer from the problem. Here is also the output of
`objdump -r' on both object files.
$ g++ -o linkonce.o -c linkonce.cc
$ objdump -r linkonce.o
linkonce.o: file format pe-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000015 DISP32 __alloca
0000001a DISP32 ___main
RELOCATION RECORDS FOR [.some_section1_text]:
OFFSET TYPE VALUE
00000001 dir32 .some_section1_text
00000007 dir32 _label_1
RELOCATION RECORDS FOR [.some_section2_text]:
OFFSET TYPE VALUE
00000001 dir32 .some_section2_text
00000007 dir32 _label_2+0xffffffee
RELOCATION RECORDS FOR [.some_section3_text]:
OFFSET TYPE VALUE
00000001 dir32 .some_section3_text
00000007 dir32 _label_3+0xffffffe3
$ g++ -o linkonce1.o -c linkonce1.cc
$ objdump -r linkonce1.o
linkonce1.o: file format pe-i386
RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000015 DISP32 __alloca
0000001a DISP32 ___main
RELOCATION RECORDS FOR [.some_section1_text]:
OFFSET TYPE VALUE
00000001 dir32 .some_section1_text
00000007 dir32 .some_section
RELOCATION RECORDS FOR [.some_section2_text]:
OFFSET TYPE VALUE
00000001 dir32 .some_section2_text
00000007 dir32 .some_section
RELOCATION RECORDS FOR [.some_section3_text]:
OFFSET TYPE VALUE
00000001 dir32 .some_section3_text
00000007 dir32 .some_section
__asm__ (" \n\
.section .some_section,\"w\" \n\
_label_1: \n\
.long 0x12345678 \n\
.asciz \"Hello, World!\" \n\
.text \n\
");
__asm__ (" \n\
.section .some_section,\"w\" \n\
_label_2: \n\
.long 0x12345678 \n\
.asciz \"abcdef\" \n\
.text \n\
");
__asm__ (" \n\
.section .some_section,\"w\" \n\
_label_3: \n\
.long 0x12345678 \n\
.asciz \"xyz\" \n\
.text \n\
");
__asm__ (" \n\
.section .some_section1_text,\"wx\" \n\
.align 8 \n\
movl (1f),%eax \n\
call *(%eax) \n\
1:.long _label_1 \n\
.text \n\
");
__asm__ (" \n\
.section .some_section2_text,\"wx\" \n\
.align 8 \n\
movl (1f),%eax \n\
call *(%eax) \n\
1:.long _label_2 \n\
.text \n\
");
__asm__ (" \n\
.section .some_section3_text,\"wx\" \n\
.align 8 \n\
movl (1f),%eax \n\
call *(%eax) \n\
1:.long _label_3 \n\
.text \n\
");
int main (int argc, char **argv)
{
return 0;
}
__asm__ (" \n\
.section .some_section,\"w\" \n\
.linkonce \n\
_label_1: \n\
.long 0x12345678 \n\
.asciz \"Hello, World!\" \n\
.text \n\
");
__asm__ (" \n\
.section .some_section,\"w\" \n\
.linkonce \n\
_label_2: \n\
.long 0x12345678 \n\
.asciz \"abcdef\" \n\
.text \n\
");
__asm__ (" \n\
.section .some_section,\"w\" \n\
.linkonce \n\
_label_3: \n\
.long 0x12345678 \n\
.asciz \"xyz\" \n\
.text \n\
");
__asm__ (" \n\
.section .some_section1_text,\"wx\" \n\
.align 8 \n\
movl (1f),%eax \n\
call *(%eax) \n\
1:.long _label_1 \n\
.text \n\
");
__asm__ (" \n\
.section .some_section2_text,\"wx\" \n\
.align 8 \n\
movl (1f),%eax \n\
call *(%eax) \n\
1:.long _label_2 \n\
.text \n\
");
__asm__ (" \n\
.section .some_section3_text,\"wx\" \n\
.align 8 \n\
movl (1f),%eax \n\
call *(%eax) \n\
1:.long _label_3 \n\
.text \n\
");
int main (int argc, char **argv)
{
return 0;
}
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/