This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: vtable pseudo ops


Bear with me here and do some babysitting please. I haven't touched this
code before and I have some problems with getting the bigger picture here.

My current problem is that I'm unsure of how to write the vtable
relocations. I don't know how to get the symbols written in the object
file so they can be picked up by the linker.

The patch below is not even work in progress, just education in progress.
It doesn't work. I need some input on how to replace the first of the
fix_new (the last one will remain there until the linker can load the new
sections) with the proper way to write the child and parent symbols along
with the offset.

And a small thing: What should the name of the sections be? I'm currently
using .vte and .vti but this does not say as much of the contents as
.vtable.entry and .vtable.inherit or .vtable_e and .vtable_i.

One last question: Does the ability to write these special sections belong
in libbfd so objcopy and others can benefit from them?

Bo.

Index: obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.29
diff -u -r1.29 obj-elf.c
--- obj-elf.c	2001/03/08 23:24:22	1.29
+++ obj-elf.c	2001/03/12 12:44:15
@@ -111,8 +111,8 @@
   {"subsection", obj_elf_subsection, 0},

   /* These are GNU extensions to aid in garbage collecting C++ vtables.  */
-  {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit, 0},
-  {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry, 0},
+  {"vtable_inherit", obj_elf_vtable_inherit, 0},
+  {"vtable_entry", obj_elf_vtable_entry, 0},

   /* These are used for dwarf.  */
   {"2byte", cons, 2},
@@ -614,6 +614,10 @@
   { ".shstrtab",SHT_STRTAB,	0				},
   { ".strtab",	SHT_STRTAB,	/* SHF_ALLOC */			},
   { ".symtab",	SHT_SYMTAB,	/* SHF_ALLOC */			},
+
+  /* Special sections to handle c++ vtable special relocations.  */
+  { ".vti",	SHT_PROGBITS,	0			},
+  { ".vte",	SHT_PROGBITS,	0			},
 #endif

   { NULL,	0,		0				}
@@ -1162,13 +1166,17 @@
    to the linker the hierarchy in which a particular table resides.  The
    syntax is ".vtable_inherit CHILDNAME, PARENTNAME".  */

-struct fix *
+void
 obj_elf_vtable_inherit (ignore)
      int ignore ATTRIBUTE_UNUSED;
 {
   char *cname, *pname;
   symbolS *csym, *psym;
   char c, bad = 0;
+  static segT vtable_entry_section;
+  segT old_section = now_seg;
+  int old_subsection = now_subseg;
+  char *p;

   if (*input_line_pointer == '#')
     ++input_line_pointer;
@@ -1195,7 +1203,7 @@
     {
       as_bad ("expected comma after name in .vtable_inherit");
       ignore_rest_of_line ();
-      return NULL;
+      return;
     }

   ++input_line_pointer;
@@ -1222,19 +1230,41 @@
   demand_empty_rest_of_line ();

   if (bad)
-    return NULL;
+    return;

   assert (symbol_get_value_expression (csym)->X_op == O_constant);
-  return fix_new (symbol_get_frag (csym),
-		  symbol_get_value_expression (csym)->X_add_number,
-		  0, psym, 0, 0, BFD_RELOC_VTABLE_INHERIT);
+
+#ifdef md_flush_pending_output
+  md_flush_pending_output ();
+#endif
+
+  if (!vtable_entry_section)
+    {
+      vtable_entry_section = subseg_new (".vte", 0);
+      bfd_set_section_flags (stdoutput, vtable_entry_section,
+			     SEC_READONLY | SEC_HAS_CONTENTS);
+    }
+  else
+    subseg_set (vtable_entry_section, 0);
+
+  /* FIXME: Write the vtable inheritance.  */
+  fix_new (symbol_get_frag (csym),
+	   symbol_get_value_expression (csym)->X_add_number,
+	   0, psym, 0, 0, BFD_RELOC_VTABLE_INHERIT);
+
+  subseg_set (old_section, old_subsection);
+
+  /* FIXME: Remove this when the above works.  */
+  fix_new (symbol_get_frag (csym),
+	   symbol_get_value_expression (csym)->X_add_number,
+	   0, psym, 0, 0, BFD_RELOC_VTABLE_INHERIT);
 }

 /* This handles the .vtable_entry pseudo-op, which is used to indicate
    to the linker that a vtable slot was used.  The syntax is
    ".vtable_entry tablename, offset".  */

-struct fix *
+void
 obj_elf_vtable_entry (ignore)
      int ignore ATTRIBUTE_UNUSED;
 {
@@ -1256,7 +1286,7 @@
     {
       as_bad ("expected comma after name in .vtable_entry");
       ignore_rest_of_line ();
-      return NULL;
+      return;
     }

   ++input_line_pointer;
@@ -1267,8 +1297,9 @@

   demand_empty_rest_of_line ();

-  return fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0,
-		  BFD_RELOC_VTABLE_ENTRY);
+/*   { ".vtable.entry",	SHT_PROGBITS,	0			}, */
+  fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0,
+	   BFD_RELOC_VTABLE_ENTRY);
 }

 void
Index: obj-elf.h
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.h,v
retrieving revision 1.14
diff -u -r1.14 obj-elf.h
--- obj-elf.h	2001/03/08 23:24:22	1.14
+++ obj-elf.h	2001/03/12 12:44:15
@@ -163,8 +163,8 @@
 extern void obj_elf_common PARAMS ((int));
 extern void obj_elf_data PARAMS ((int));
 extern void obj_elf_text PARAMS ((int));
-extern struct fix *obj_elf_vtable_inherit PARAMS ((int));
-extern struct fix *obj_elf_vtable_entry PARAMS ((int));
+extern void obj_elf_vtable_inherit PARAMS ((int));
+extern void obj_elf_vtable_entry PARAMS ((int));

 /* BFD wants to write the udata field, which is a no-no for the
    globally defined sections.  */

-- 

     Bo Thorsen                 |   Lahnsgade 31, st.
     Free software developer    |   5000 Odense C
     SuSE Labs                  |   Denmark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]