This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: TLS orphan section placement
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Fri, 24 Jan 2014 09:07:12 -0800
- Subject: Re: TLS orphan section placement
- Authentication-results: sourceware.org; auth=none
- References: <20140122193013 dot GA4156 at intel dot com> <20140123035510 dot GZ5390 at bubble dot grove dot modra dot org> <CAMe9rOq6KvUnsrzQTEBE9XzHM8DKC4UaWqLet_NgReVE0kCT-A at mail dot gmail dot com> <20140124125357 dot GF5390 at bubble dot grove dot modra dot org>
On Fri, Jan 24, 2014 at 4:53 AM, Alan Modra <amodra@gmail.com> wrote:
> On Wed, Jan 22, 2014 at 08:19:31PM -0800, H.J. Lu wrote:
>> On Wed, Jan 22, 2014 at 7:55 PM, Alan Modra <amodra@gmail.com> wrote:
>> > On Wed, Jan 22, 2014 at 11:30:13AM -0800, H.J. Lu wrote:
>> >> PR ld/16498
>> >> * elf.c (_bfd_elf_map_sections_to_segments): Issue a linker error
>> >> if TLS sections are not adjacent.
>> >
>> > This part is OK.
>>
>> I'd like to augment my patch like
>
> Yes, this is OK too.
>
>> > On the other hand, the testcase is really showing a fault in orphan
>> > section handling. If ld was a little more clever, it would put .tbss
>> > after .tdata and your testcase would no longer give an error.
>> >
>>
>> I am enclosing a simple patch which does it. However, it
>> doesn't solve the second testcase in the bug report since
>> it has a linker script:
>>
>> ---
>> SECTIONS
>> {
>> tls_data_init : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
>> .data :
>> {
>> *(.data .data.* .gnu.linkonce.d.*)
>> }
>> /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
>> }
>> ---
>
> Besides the place_orphan change you posted, which is OK to commit,
> you need something like the following.
>
> Ensures TLS orphans are placed adjacent to existing TLS sections,
> and fixes places where the output_section_statement flags (which might
> not be set) were tested when bfd_section flags were available.
>
> * ldlang.c (lang_output_section_find_by_flags): Be careful to
> test look->bfd_section->flags if available rather than
> look->flags. Separate SEC_THREAD_LOCAL handling from
> SEC_READONLY loop, and rewrite.
>
These are 2 patches I checked in.
Thanks.
--
H.J.
From d85e71fec0aa4d9d8ca0d8c2401cd8ab69fe2edc Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 22 Jan 2014 11:24:12 -0800
Subject: [PATCH 1/2] Improve orphaned TLS section handling
ld/
PR ld/16498
* emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Improve
orphaned TLS section handling.
ld/testsuite/
PR ld/16498
* ld-elf/pr16498a.d: New file.
* ld-elf/pr16498a.s: Likewise.
* ld-elf/pr16498a.t: Likewise.
---
ld/ChangeLog | 6 ++++++
ld/emultempl/elf32.em | 6 ++++++
ld/testsuite/ChangeLog | 7 +++++++
ld/testsuite/ld-elf/pr16498a.d | 9 +++++++++
ld/testsuite/ld-elf/pr16498a.s | 23 +++++++++++++++++++++++
ld/testsuite/ld-elf/pr16498a.t | 6 ++++++
6 files changed, 57 insertions(+)
create mode 100644 ld/testsuite/ld-elf/pr16498a.d
create mode 100644 ld/testsuite/ld-elf/pr16498a.s
create mode 100644 ld/testsuite/ld-elf/pr16498a.t
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 9beee8c..dcf0b15 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,9 @@
+2014-01-24 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/16498
+ * emultempl/elf32.em (gld${EMULATION_NAME}_place_orphan): Improve
+ orphaned TLS section handling.
+
2014-01-24 Alan Modra <amodra@gmail.com>
* ldlang.c (lang_output_section_find_by_flags): Be careful to
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index a4f04f1..fda0e68 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1812,6 +1812,9 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
{ ".rodata",
SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA,
0, 0, 0, 0 },
+ { ".tdata",
+ SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_THREAD_LOCAL,
+ 0, 0, 0, 0 },
{ ".data",
SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_DATA,
0, 0, 0, 0 },
@@ -1835,6 +1838,7 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
{
orphan_text = 0,
orphan_rodata,
+ orphan_tdata,
orphan_data,
orphan_bss,
orphan_rel,
@@ -1962,6 +1966,8 @@ gld${EMULATION_NAME}_place_orphan (asection *s,
place = &hold[orphan_bss];
else if ((s->flags & SEC_SMALL_DATA) != 0)
place = &hold[orphan_sdata];
+ else if ((s->flags & SEC_THREAD_LOCAL) != 0)
+ place = &hold[orphan_tdata];
else if ((s->flags & SEC_READONLY) == 0)
place = &hold[orphan_data];
else if (((iself && (sh_type == SHT_RELA || sh_type == SHT_REL))
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index a269b07..4f0a75b 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2014-01-24 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/16498
+ * ld-elf/pr16498a.d: New file.
+ * ld-elf/pr16498a.s: Likewise.
+ * ld-elf/pr16498a.t: Likewise.
+
2014-01-22 Alan Modra <amodra@gmail.com>
* ld-scripts/pr14962-2.d: Correct target triple.
diff --git a/ld/testsuite/ld-elf/pr16498a.d b/ld/testsuite/ld-elf/pr16498a.d
new file mode 100644
index 0000000..436bf97
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr16498a.d
@@ -0,0 +1,9 @@
+#ld: -shared -T pr16498a.t
+#readelf: -l --wide
+#target: *-*-linux* *-*-gnu* *-*-nacl*
+
+#...
+ TLS .*
+#...
+[ ]+[0-9]+[ ]+.tdata .tbss[ ]*
+#pass
diff --git a/ld/testsuite/ld-elf/pr16498a.s b/ld/testsuite/ld-elf/pr16498a.s
new file mode 100644
index 0000000..77f80e6
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr16498a.s
@@ -0,0 +1,23 @@
+ .globl data
+ .data
+ .align 32
+ .type data, %object
+ .size data, 120
+data:
+ .long 1
+ .zero 116
+ .globl foo
+ .section .tbss,"awT",%nobits
+ .align 4
+ .type foo, %object
+ .size foo, 4
+foo:
+ .zero 4
+ .globl bar
+ .section .tdata,"awT",%progbits
+ .align 16
+ .type bar, %object
+ .size bar, 80
+bar:
+ .long 1
+ .zero 76
diff --git a/ld/testsuite/ld-elf/pr16498a.t b/ld/testsuite/ld-elf/pr16498a.t
new file mode 100644
index 0000000..928724f
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr16498a.t
@@ -0,0 +1,6 @@
+SECTIONS
+{
+ .tdata : { *(.tdata) }
+ .data : { *(.data)
+ }
+}
--
1.8.4.2
From a78ad74bbfbe2bee6b2909e9574892d38082e4ea Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Fri, 24 Jan 2014 09:03:21 -0800
Subject: [PATCH 2/2] Add another testcase for PR ld/16498
PR ld/16498
* ld-elf/pr16498b.d: New file.
* ld-elf/pr16498b.t: Likewise.
---
ld/testsuite/ChangeLog | 6 ++++++
ld/testsuite/ld-elf/pr16498b.d | 10 ++++++++++
ld/testsuite/ld-elf/pr16498b.t | 6 ++++++
3 files changed, 22 insertions(+)
create mode 100644 ld/testsuite/ld-elf/pr16498b.d
create mode 100644 ld/testsuite/ld-elf/pr16498b.t
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 4f0a75b..9e8553a 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,6 +1,12 @@
2014-01-24 H.J. Lu <hongjiu.lu@intel.com>
PR ld/16498
+ * ld-elf/pr16498b.d: New file.
+ * ld-elf/pr16498b.t: Likewise.
+
+2014-01-24 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/16498
* ld-elf/pr16498a.d: New file.
* ld-elf/pr16498a.s: Likewise.
* ld-elf/pr16498a.t: Likewise.
diff --git a/ld/testsuite/ld-elf/pr16498b.d b/ld/testsuite/ld-elf/pr16498b.d
new file mode 100644
index 0000000..c70c239
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr16498b.d
@@ -0,0 +1,10 @@
+#source: pr16498a.s
+#ld: -shared -T pr16498b.t
+#readelf: -l --wide
+#target: *-*-linux* *-*-gnu* *-*-nacl*
+
+#...
+ TLS .*
+#...
+[ ]+[0-9]+[ ]+tls_data_init .tbss[ ]*
+#pass
diff --git a/ld/testsuite/ld-elf/pr16498b.t b/ld/testsuite/ld-elf/pr16498b.t
new file mode 100644
index 0000000..b88f9b8
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr16498b.t
@@ -0,0 +1,6 @@
+SECTIONS
+{
+ tls_data_init : { *(.tdata) }
+ .data : { *(.data)
+ }
+}
--
1.8.4.2