* [PATCH] gold: Fix segfault on sparc with STT_SPARC_REGISTER and --gc-sections
@ 2016-07-24 17:46 James Clarke
2016-08-10 18:14 ` Cary Coutant
0 siblings, 1 reply; 2+ messages in thread
From: James Clarke @ 2016-07-24 17:46 UTC (permalink / raw)
To: binutils; +Cc: James Clarke, Cary Coutant
gold/
* symtab.cc (Symbol_table::add_from_relobj): Handle NULL symbols,
which will be present for STT_SPARC_REGISTER.
(Symbol_table::add_from_pluginobj): Likewise.
(Symbol_table::add_from_dynobj): Likewise.
(Symbol_table::add_from_incrobj): Removed dead code.
---
Easy reproduction:
$ cat main.c
int main() {
return 0;
}
$ gcc -o main -Wl,--gc-sections main.c
$ gcc -fuse-ld=gold -o main -Wl,--gc-sections main.c
collect2: fatal error: ld terminated with signal 11 [Segmentation fault]
compilation terminated.
This is because res->is_externally_visible inside Symbol_table::add_from_relobj
when res is NULL (since this is an STT_SPARC_REGISTER dummy symbol).
With this patch I've done the obvious bare minimum to get this to work, but
given these NULLs are floating around now I highly suspect there will be other
places where they crop up.
gold/symtab.cc | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/gold/symtab.cc b/gold/symtab.cc
index 5ce5c31..b31794a 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -1325,6 +1325,9 @@ Symbol_table::add_from_relobj(
res = this->add_from_object(relobj, name, name_key, ver, ver_key,
is_default_version, *psym, st_shndx,
is_ordinary, orig_st_shndx);
+
+ if (res == NULL)
+ continue;
if (is_forced_local)
this->force_local(res);
@@ -1406,6 +1409,9 @@ Symbol_table::add_from_pluginobj(
is_default_version, *sym, st_shndx,
is_ordinary, st_shndx);
+ if (res == NULL)
+ return NULL;
+
if (is_forced_local)
this->force_local(res);
@@ -1602,6 +1608,9 @@ Symbol_table::add_from_dynobj(
}
}
+ if (res == NULL)
+ continue;
+
// Note that it is possible that RES was overridden by an
// earlier object, in which case it can't be aliased here.
if (st_shndx != elfcpp::SHN_UNDEF
@@ -1640,7 +1649,6 @@ Symbol_table::add_from_incrobj(
Stringpool::Key ver_key = 0;
bool is_default_version = false;
- bool is_forced_local = false;
Stringpool::Key name_key;
name = this->namepool_.add(name, true, &name_key);
@@ -1650,9 +1658,6 @@ Symbol_table::add_from_incrobj(
is_default_version, *sym, st_shndx,
is_ordinary, st_shndx);
- if (is_forced_local)
- this->force_local(res);
-
return res;
}
--
2.9.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gold: Fix segfault on sparc with STT_SPARC_REGISTER and --gc-sections
2016-07-24 17:46 [PATCH] gold: Fix segfault on sparc with STT_SPARC_REGISTER and --gc-sections James Clarke
@ 2016-08-10 18:14 ` Cary Coutant
0 siblings, 0 replies; 2+ messages in thread
From: Cary Coutant @ 2016-08-10 18:14 UTC (permalink / raw)
To: James Clarke; +Cc: Binutils
> gold/
> * symtab.cc (Symbol_table::add_from_relobj): Handle NULL symbols,
> which will be present for STT_SPARC_REGISTER.
> (Symbol_table::add_from_pluginobj): Likewise.
> (Symbol_table::add_from_dynobj): Likewise.
> (Symbol_table::add_from_incrobj): Removed dead code.
This is OK. I've committed it to master and backported it to the 2.27 branch.
Thanks!
-cary
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-10 18:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-24 17:46 [PATCH] gold: Fix segfault on sparc with STT_SPARC_REGISTER and --gc-sections James Clarke
2016-08-10 18:14 ` Cary Coutant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).