This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
PATCH: elf32-i386.c
- To: David Mosberger <davidm at hpl dot hp dot com>
- Subject: PATCH: elf32-i386.c
- From: "H . J . Lu" <hjl at lucon dot org>
- Date: Thu, 5 Apr 2001 17:40:26 -0700
- Cc: michael dot johnston at intel dot com, eranian at napali dot hpl dot hp dot com,binutils at sourceware dot cygnus dot com
- References: <D5E932F578EBD111AC3F00A0C96B1E6F061BDF4F@orsmsx31.jf.intel.com> <20010402231821.A11383@lucon.org> <15049.33067.831028.656080@napali.hpl.hp.com> <20010403074235.A18492@lucon.org> <15052.63447.446229.552187@napali.hpl.hp.com>
On Thu, Apr 05, 2001 at 03:55:19PM -0700, David Mosberger wrote:
> >>>>> On Tue, 3 Apr 2001 07:42:35 -0700, "H . J . Lu" <hjl@lucon.org> said:
>
> HJ> David, I want to avoid changing ELF bfd if all possible.
>
> Me too.
>
> HJ> Could you please try
>
> HJ> .section .reloc, "a",@progbits
>
> HJ> instead of
>
> HJ> .section .reloc, "a"
>
> The problem is that BFD completely ignored the incoming section type.
> It's the stupid name-based matching that's causing the problem. If
> you can come up with a better fix, that would be great. I did talk to
> Richard Henderson a few months ago and he couldn't come up with a
> better idea either.
>
Ok. I checked this into CVS.
Thanks.
H.J.
----
2001-03-29 David Mosberger <davidm@hpl.hp.com>
* elf32-i386.c (elf_i386_fake_sections): Treat ".reloc" as an
ordinary "progbits" section.
--- elf32-i386.c.~1.23.~ Thu Mar 8 13:03:59 2001
+++ elf32-i386.c Thu Mar 29 19:47:33 2001
@@ -2066,6 +2066,44 @@
return true;
}
+/* Set the correct type for an x86 ELF section. We do this by the
+ section name, which is a hack, but ought to work. */
+
+static boolean
+elf_i386_fake_sections (abfd, hdr, sec)
+ bfd *abfd ATTRIBUTE_UNUSED;
+ Elf32_Internal_Shdr *hdr;
+ asection *sec;
+{
+ register const char *name;
+
+ name = bfd_get_section_name (abfd, sec);
+
+ if (strcmp (name, ".reloc") == 0)
+ /*
+ * This is an ugly, but unfortunately necessary hack that is
+ * needed when producing EFI binaries on x86. It tells
+ * elf.c:elf_fake_sections() not to consider ".reloc" as a section
+ * containing ELF relocation info. We need this hack in order to
+ * be able to generate ELF binaries that can be translated into
+ * EFI applications (which are essentially COFF objects). Those
+ * files contain a COFF ".reloc" section inside an ELFNN object,
+ * which would normally cause BFD to segfault because it would
+ * attempt to interpret this section as containing relocation
+ * entries for section "oc". With this hack enabled, ".reloc"
+ * will be treated as a normal data section, which will avoid the
+ * segfault. However, you won't be able to create an ELFNN binary
+ * with a section named "oc" that needs relocations, but that's
+ * the kind of ugly side-effects you get when detecting section
+ * types based on their names... In practice, this limitation is
+ * unlikely to bite.
+ */
+ hdr->sh_type = SHT_PROGBITS;
+
+ return true;
+}
+
+
#define TARGET_LITTLE_SYM bfd_elf32_i386_vec
#define TARGET_LITTLE_NAME "elf32-i386"
#define ELF_ARCH bfd_arch_i386
@@ -2096,5 +2134,6 @@
#define elf_backend_gc_sweep_hook elf_i386_gc_sweep_hook
#define elf_backend_relocate_section elf_i386_relocate_section
#define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections
+#define elf_backend_fake_sections elf_i386_fake_sections
#include "elf32-target.h"