This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Patch for retaining relocation entries in executable objects
- To: GNU binutils <binutils at sourceware dot cygnus dot com>
- Subject: Patch for retaining relocation entries in executable objects
- From: Momchil Velikov <velco at fadata dot bg>
- Date: Fri, 10 Mar 2000 01:43:17 +0200
Hi, folks.
This patch:
* adds the field 'boolean retain_relocs;' to struct bfd_link_info;
* adds the command line option --retain-relocs to ld -- when given
sets the above field to true.
* modifies bfd/elflink.h so the relocation entries are output if
--retain-relocs is given on the command line.
Without the patch, I was unable to found any other way to execute
multiple processes on platforms without a MMU.
What do you think ?
Regards,
-velco
diff -ur binutils-2.9.5.0.24.orig/bfd/elflink.h binutils-2.9.5.0.24/bfd/elflink.h
--- binutils-2.9.5.0.24.orig/bfd/elflink.h Thu Jan 13 21:52:34 2000
+++ binutils-2.9.5.0.24/bfd/elflink.h Mon Mar 06 19:22:00 2000
@@ -4166,7 +4166,7 @@
the linker has decided to not include. */
sec->linker_mark = true;
- if (info->relocateable)
+ if (info->relocateable || info->retain_relocs )
o->reloc_count += sec->reloc_count;
if (sec->_raw_size > max_contents_size)
@@ -4234,7 +4234,7 @@
/* Figure out how many relocations we will have in each section.
Just using RELOC_COUNT isn't good enough since that doesn't
maintain a separate value for REL vs. RELA relocations. */
- if (info->relocateable)
+ if (info->relocateable || info->retain_relocs )
for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
for (o = sub->sections; o != NULL; o = o->next)
{
@@ -5553,7 +5553,7 @@
finfo->sections))
return false;
- if (finfo->info->relocateable)
+ if (finfo->info->relocateable || finfo->info->retain_relocs )
{
Elf_Internal_Rela *irela;
Elf_Internal_Rela *irelaend;
@@ -5574,7 +5574,10 @@
Elf_Internal_Sym *isym;
asection *sec;
- irela->r_offset += o->output_offset;
+ if (finfo->info->relocateable )
+ irela->r_offset += o->output_offset;
+ else
+ irela->r_offset += o->output_offset + o->output_section->vma;
r_symndx = ELF_R_SYM (irela->r_info);
diff -ur binutils-2.9.5.0.24.orig/include/bfdlink.h binutils-2.9.5.0.24/include/bfdlink.h
--- binutils-2.9.5.0.24.orig/include/bfdlink.h Sun Jun 27 03:03:06 1999
+++ binutils-2.9.5.0.24/include/bfdlink.h Mon Mar 06 18:43:10 2000
@@ -179,6 +179,8 @@
const struct bfd_link_callbacks *callbacks;
/* true if BFD should generate a relocateable object file. */
boolean relocateable;
+ /* true if BFD should retain relocation entries even if not generating a relocateable object file. */
+ boolean retain_relocs;
/* true if BFD should generate a "task linked" object file,
similar to relocatable but also with globals converted to statics. */
boolean task_link;
diff -ur binutils-2.9.5.0.24.orig/ld/ldmain.c binutils-2.9.5.0.24/ld/ldmain.c
--- binutils-2.9.5.0.24.orig/ld/ldmain.c Thu Jan 13 20:24:40 2000
+++ binutils-2.9.5.0.24/ld/ldmain.c Mon Mar 06 16:06:38 2000
@@ -215,6 +215,7 @@
link_info.callbacks = &link_callbacks;
link_info.relocateable = false;
+ link_info.retain_relocs = false;
link_info.shared = false;
link_info.symbolic = false;
link_info.static_link = false;
diff -ur binutils-2.9.5.0.24.orig/ld/lexsup.c binutils-2.9.5.0.24/ld/lexsup.c
--- binutils-2.9.5.0.24.orig/ld/lexsup.c Sun Oct 10 20:23:22 1999
+++ binutils-2.9.5.0.24/ld/lexsup.c Mon Mar 06 16:06:02 2000
@@ -89,7 +89,8 @@
#define OPTION_NO_WHOLE_ARCHIVE (OPTION_NON_SHARED + 1)
#define OPTION_OFORMAT (OPTION_NO_WHOLE_ARCHIVE + 1)
#define OPTION_RELAX (OPTION_OFORMAT + 1)
-#define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1)
+#define OPTION_RETAIN_RELOCS (OPTION_RELAX + 1)
+#define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RETAIN_RELOCS + 1)
#define OPTION_RPATH (OPTION_RETAIN_SYMBOLS_FILE + 1)
#define OPTION_RPATH_LINK (OPTION_RPATH + 1)
#define OPTION_SHARED (OPTION_RPATH_LINK + 1)
@@ -317,6 +318,9 @@
'\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
{ {"relax", no_argument, NULL, OPTION_RELAX},
'\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES },
+ { {"retain-relocs", no_argument, NULL,
+ OPTION_RETAIN_RELOCS},
+ '\0', NULL, N_("Retain relocations"), TWO_DASHES },
{ {"retain-symbols-file", required_argument, NULL,
OPTION_RETAIN_SYMBOLS_FILE},
'\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
@@ -813,6 +817,9 @@
break;
case OPTION_RELAX:
command_line.relax = true;
+ break;
+ case OPTION_RETAIN_RELOCS:
+ link_info.retain_relocs = true;
break;
case OPTION_RETAIN_SYMBOLS_FILE:
add_keepsyms_file (optarg);