This is the mail archive of the
binutils-cvs@sourceware.org
mailing list for the binutils project.
[binutils-gdb] ld: Don't define __start_SECNAME/__stop_SECNAME for -r
- From: H.J.Lu <hjl at sourceware dot org>
- To: bfd-cvs at sourceware dot org
- Date: 13 Jun 2017 20:05:13 -0000
- Subject: [binutils-gdb] ld: Don't define __start_SECNAME/__stop_SECNAME for -r
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b27685f2016c510d03ac9a64f7b04ce8efcf95c4
commit b27685f2016c510d03ac9a64f7b04ce8efcf95c4
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Tue Jun 13 13:04:56 2017 -0700
ld: Don't define __start_SECNAME/__stop_SECNAME for -r
__start_SECNAME and __stop_SECNAME shouldn't be defined for "ld -r".
* ldlang.c (lang_set_startof): Skip if config.build_constructors
is FALSE.
* testsuite/ld-elf/sizeofc.d: New file.
* testsuite/ld-elf/startofc.d: Likewise.
Diff:
---
ld/ChangeLog | 7 +++++++
ld/ldlang.c | 14 ++++++++++----
ld/testsuite/ld-elf/sizeofc.d | 12 ++++++++++++
ld/testsuite/ld-elf/startofc.d | 12 ++++++++++++
4 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 59c99ae..7995de8 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,12 @@
2017-06-13 H.J. Lu <hongjiu.lu@intel.com>
+ * ldlang.c (lang_set_startof): Skip if config.build_constructors
+ is FALSE.
+ * testsuite/ld-elf/sizeofc.d: New file.
+ * testsuite/ld-elf/startofc.d: Likewise.
+
+2017-06-13 H.J. Lu <hongjiu.lu@intel.com>
+
* testsuite/ld-elf/sizeof.d: Renamed to ...
* testsuite/ld-elf/sizeofa.d: This. Updated.
* testsuite/ld-elf/startof.d: Renamed to ...
diff --git a/ld/ldlang.c b/ld/ldlang.c
index f8e4f52..eb4ba9e 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5892,9 +5892,15 @@ lang_set_startof (void)
{
asection *s;
char leading_char;
- bfd_boolean is_elf = (bfd_get_flavour (link_info.output_bfd)
- == bfd_target_elf_flavour);
- bfd_boolean is_elocatable = bfd_link_relocatable (&link_info);
+ bfd_boolean is_elf;
+ bfd_boolean is_relocatable;
+
+ if (!config.build_constructors)
+ return;
+
+ is_elf = (bfd_get_flavour (link_info.output_bfd)
+ == bfd_target_elf_flavour);
+ is_relocatable = bfd_link_relocatable (&link_info);
leading_char = bfd_get_symbol_leading_char (link_info.output_bfd);
@@ -5907,7 +5913,7 @@ lang_set_startof (void)
secname = bfd_get_section_name (link_info.output_bfd, s);
buf = (char *) xmalloc (10 + strlen (secname));
- if (!is_elocatable)
+ if (!is_relocatable)
{
sprintf (buf, ".startof.%s", secname);
h = bfd_link_hash_lookup (link_info.hash, buf, FALSE, FALSE,
diff --git a/ld/testsuite/ld-elf/sizeofc.d b/ld/testsuite/ld-elf/sizeofc.d
new file mode 100644
index 0000000..1cff854
--- /dev/null
+++ b/ld/testsuite/ld-elf/sizeofc.d
@@ -0,0 +1,12 @@
+#source: sizeof.s
+#ld: -r
+#readelf: -sW
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +__stop_scnfoo
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +.sizeof.scnfoo
+#pass
diff --git a/ld/testsuite/ld-elf/startofc.d b/ld/testsuite/ld-elf/startofc.d
new file mode 100644
index 0000000..4005625
--- /dev/null
+++ b/ld/testsuite/ld-elf/startofc.d
@@ -0,0 +1,12 @@
+#source: startof.s
+#ld: -r
+#readelf: -sW
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+ +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +.startof.scnfoo
+#...
+ +[0-9]+: +[a-f0-9]+ +0 +NOTYPE +GLOBAL +DEFAULT +UND +__start_scnfoo
+#pass