This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
ld crash when PHDRS uses undefined names
- From: Roland McGrath <roland at redhat dot com>
- To: binutils at sources dot redhat dot com
- Date: Wed, 23 Apr 2003 01:41:40 -0700
- Subject: ld crash when PHDRS uses undefined names
If a PHDRS statement uses unrecognized names for phdr types, ld crashes.
A test case is easy to concoct. This patch makes unrecognized names a
graceful error, and also makes it grok the recently added PT_* names.
I put the literal value for PT_GNU_EH_FRAME in there instead of futzing
with header inclusion, since it keeps the change simple and the array there
already implicits hard-codes literal values for the low-valued PT_* names.
The "$$ = exp_intop (0);" sets a bogus value when a bad name was diagnosed.
That prevents it from crashing later on. I don't know if there is a better
way to do it.
Someone gave me write access at some point, so I can commit with approval
if that is most convenient for whoever does the approving.
Thanks,
Roland
2003-04-23 Roland McGrath <roland at redhat dot com>
* ldgram.y (phdr_type): Grok PT_TLS and PT_GNU_EH_FRAME names.
If a name string is unknown, give an error rather than crashing later.
--- binutils/ld/ldgram.y.~1.24.~ Fri Feb 28 12:22:01 2003
+++ binutils/ld/ldgram.y Wed Apr 23 01:32:20 2003
@@ -990,7 +990,7 @@ phdr_type:
{
"PT_NULL", "PT_LOAD", "PT_DYNAMIC",
"PT_INTERP", "PT_NOTE", "PT_SHLIB",
- "PT_PHDR"
+ "PT_PHDR", "PT_TLS"
};
s = $1->name.name;
@@ -1002,6 +1002,18 @@ phdr_type:
$$ = exp_intop (i);
break;
}
+ if (i == sizeof phdr_types / sizeof phdr_types[0])
+ {
+ if (strcmp (s, "PT_GNU_EH_FRAME") == 0)
+ $$ = exp_intop (0x6474e550);
+ else
+ {
+ einfo (_("\
+%X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
+ s);
+ $$ = exp_intop (0);
+ }
+ }
}
}
;