This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] fix underfined Thumb symbols


Hello!

For ARM EABI, the low bit of st_value field of function symbols is used to 
indicate the thumbness of the symbol. However, this low bit is set not only
for symbols defined in an object, but also for underfined symbols.

Suppose libfoo.so defines thumb symbol foo, and libbar.so uses foo and links 
to libfoo.so. The static linker, when creating 'libbar.so', will carry over
thumbness of 'foo' into libbar.so's symbol table, like this:

   6   2: 00000001     2    FUNC GLOBAL DEFAULT UND foo

This is not quite right:

1. At runtime, the symbol 'foo' in libfoo.so might no longer be Thumb symbol.
And ifs it's Thumb symbol, dynamic linker will handle this just fine anyway, 
without that low bit hint.
2. The '1' address can be confusing for user and for dynamic linker, as
usually non-null values of underfined symbols are used in main executable to
refer to PLT entries.

The attached patch fixes this by not setting the low bit when writing 
underfined Thumb symbols.

Tested with cross to arm-none-linux-gnueabi.

bfd/
2006-06-17  Vladimir Prus  <vladimir@codesourcery.com>

	* elf32-arm.c (elf32_arm_swap_symbol_out): Don't set low
    bit for underfined symbols.

ld/testsuite
2006-06-17  Vladimir Prus  <vladimir@codesourcery.com>

    * ld-arm/arm-elf.exp: New test.
    * ld-arm/use-thumb-lib.s: New file.
    * ld-arm/usr-thumb-lib.sym: New file.



- Volodya


diff -Nru pristine/bfd/elf32-arm.c work/bfd/elf32-arm.c
--- pristine/bfd/elf32-arm.c	2006-06-15 04:03:00.000000000 -0700
+++ work/bfd/elf32-arm.c	2006-06-17 01:11:00.000000000 -0700
@@ -9172,6 +9172,19 @@
     {
       newsym = *src;
       newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
+      if (newsym.st_shndx != SHN_UNDEF)
+        {
+          /* Do this only for defined symbols. At link type, the static
+             linker will simulate the work of dynamic linker of resolving
+             symbols and will carry over the thumbness of found symbols to
+             the output symbol table. It's not clear how it happens, but
+             the thumbness of underfined symbols can well be different at
+             runtime, and writing '1' for them will be confusing for users
+             and possibly for dynamic linker itself.
+          */
+          newsym.st_value |= 1;
+        }
+
       newsym.st_value |= 1;
       
       src = &newsym;
diff -Nru pristine/ld/testsuite/ld-arm/arm-elf.exp work/ld/testsuite/ld-arm/arm-elf.exp
--- pristine/ld/testsuite/ld-arm/arm-elf.exp	2006-06-15 04:03:02.000000000 -0700
+++ work/ld/testsuite/ld-arm/arm-elf.exp	2006-06-17 01:16:06.000000000 -0700
@@ -131,6 +131,10 @@
     {"BE8 Mapping Symbols" "-static -T arm.ld -EB --be8" "-EB" {arm-be8.s}
      {{objdump -s arm-be8.d}}
      "arm-be8"}
+    {"Using Thumb lib by another lib" "-shared tmpdir/mixed-lib.so" "" {use-thumb-lib.s}
+     {{readelf -Ds use-thumb-lib.sym}}
+     "use-thumb-lib.so"}
+
 }
 
 run_ld_link_tests $armelftests
diff -Nru pristine/ld/testsuite/ld-arm/use-thumb-lib.s work/ld/testsuite/ld-arm/use-thumb-lib.s
--- pristine/ld/testsuite/ld-arm/use-thumb-lib.s	1969-12-31 16:00:00.000000000 -0800
+++ work/ld/testsuite/ld-arm/use-thumb-lib.s	2006-06-16 09:41:59.000000000 -0700
@@ -0,0 +1,25 @@
+	.cpu arm10tdmi
+	.fpu softvfp
+	.eabi_attribute 18, 4
+	.eabi_attribute 20, 1
+	.eabi_attribute 21, 1
+	.eabi_attribute 23, 3
+	.eabi_attribute 24, 1
+	.eabi_attribute 25, 1
+	.eabi_attribute 26, 2
+	.eabi_attribute 30, 6
+	.file	"use_thumb_lib.c"
+	.text
+	.align	2
+	.global	foo
+	.type	foo, %function
+foo:
+	@ args = 0, pretend = 0, frame = 0
+	@ frame_needed = 1, uses_anonymous_args = 0
+	mov	ip, sp
+	stmfd	sp!, {fp, ip, lr, pc}
+	sub	fp, ip, #4
+	bl	lib_func2
+	ldmfd	sp, {fp, sp, pc}
+	.size	foo, .-foo
+	.ident	"GCC: (GNU) 4.1.0 (CodeSourcery ARM 2006q1-7)"
diff -Nru pristine/ld/testsuite/ld-arm/use-thumb-lib.sym work/ld/testsuite/ld-arm/use-thumb-lib.sym
--- pristine/ld/testsuite/ld-arm/use-thumb-lib.sym	1969-12-31 16:00:00.000000000 -0800
+++ work/ld/testsuite/ld-arm/use-thumb-lib.sym	2006-06-16 09:41:59.000000000 -0700
@@ -0,0 +1,15 @@
+
+Symbol table for image:
+  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name
+   11   0: 0000830c     0  NOTYPE GLOBAL DEFAULT ABS _edata
+   10   0: 00000268    20    FUNC GLOBAL DEFAULT   6 foo
+    4   0: 0000830c     0  NOTYPE GLOBAL DEFAULT ABS __bss_start__
+   12   1: 0000830c     0  NOTYPE GLOBAL DEFAULT ABS _end
+    7   1: 0000830c     0  NOTYPE GLOBAL DEFAULT ABS __bss_end__
+    5   1: 0000027c     0  NOTYPE GLOBAL DEFAULT ABS __exidx_start
+   13   2: 0000830c     0  NOTYPE GLOBAL DEFAULT ABS __data_start
+    9   2: 0000830c     0  NOTYPE GLOBAL DEFAULT ABS __end__
+    8   2: 0000830c     0  NOTYPE GLOBAL DEFAULT ABS __bss_start
+    6   2: 00000000     2    FUNC GLOBAL DEFAULT UND lib_func2
+    3   2: 0000830c     0  NOTYPE GLOBAL DEFAULT ABS _bss_end__
+    2   2: 0000027c     0  NOTYPE GLOBAL DEFAULT ABS __exidx_end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]