This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [lto][patch] Add a program to read IL symbol tables


On 8/20/08 11:31 AM, Rafael Espindola wrote:
The plug-in should also share the same logic for finding libelf that
gcc/configure.ac has - allowing for possible different names for the
libelf header, and, should a --with-libelf option be added in future as
per <http://gcc.gnu.org/ml/gcc/2007-09/msg00117.html>, honouring that.
Thus I recommend putting that logic in a shared macro in config/, and
making sure the C sources allow for the different header names.
Will work on that.

The attached patch fixes it. Is it OK?

I have no opinion on the configure and Makefile machinery. I will defer to Joseph for that.


One comment about code organization. I'm thinking that we probably want to work on a generic API set for external programs to manipulate the .lto files. In this case, we only need to read the symbol table, but in other cases, tools will may want to do more manipulation.

How about introducing a liblto directory?

diff --git a/include/lto-symtab.h b/include/lto-symtab.h
new file mode 100644
index 0000000..e3f2cb0
--- /dev/null
+++ b/include/lto-symtab.h
@@ -0,0 +1,16 @@
+enum gcc_plugin_symbol_kind
+  {
+    GCCPK_DEF,
+    GCCPK_WEAKDEF,
+    GCCPK_UNDEF,
+    GCCPK_WEAKUNDEF,
+    GCCPK_COMMON
+  };

This file should have the same copyright headers as the other host libraries.


+
+enum gcc_plugin_symbol_visibility
+  {
+    GCCPV_DEFAULT,
+    GCCPV_PROTECTED,
+    GCCPV_INTERNAL,
+    GCCPV_HIDDEN
+  };
diff --git a/lto-plugin/Makefile.am b/lto-plugin/Makefile.am
new file mode 100644
index 0000000..db159bd
--- /dev/null
+++ b/lto-plugin/Makefile.am
@@ -0,0 +1,4 @@
+AM_CPPFLAGS = -I$(top_srcdir)/../include
+bin_PROGRAMS = ltosymtab
+ltosymtab_SOURCES = lto-symtab.c
+ltosymtab_LDADD = -lelf
diff --git a/lto-plugin/Makefile.in b/lto-plugin/Makefile.in
new file mode 100644
index 0000000..d38cdd7
--- /dev/null
+++ b/lto-plugin/Makefile.in

No need to include generated files in patches.


--- /dev/null
+++ b/lto-plugin/lto-symtab.c

This also needs copyright headers.


@@ -0,0 +1,128 @@
+#include <fcntl.h>
+#include <assert.h>
+#ifdef HAVE_LIBELF_H
+# include <libelf.h>
+#else
+# if defined(HAVE_LIBELF_LIBELF_H)
+#   include <libelf/libelf.h>
+# else
+#  error "libelf.h not available"
+# endif
+#endif
+#include <stdio.h>
+#include <string.h>
+#include "lto-symtab.h"
+
+/* Return the string table of ELF. */
+
+const char *get_string_table (Elf *elf)
+{

Formatting. Return type goes in line above.


+  Elf64_Ehdr *header = elf64_getehdr (elf);
+  assert(header);

Space before '('.


+  Elf_Scn *section = elf_getscn (elf, header->e_shstrndx);
+  assert (section);
+  Elf_Data *data = 0;
+  data = elf_getdata (section, data);
+  assert (data);
+  assert (data->d_buf);
+  return (const char *) data->d_buf;
+}
+
+/* Return the section in ELF that is named NAME. */
+
+Elf_Scn *get_section (Elf *elf, const char *name)
+{

Formatting. Return type goes in line above. Happens a few times throughout the file.


+  const char *string_table = get_string_table (elf);
+  Elf_Scn *section = 0;
+  while ((section = elf_nextscn(elf, section)) != 0) {

Brace goes in line below.


+    Elf64_Shdr *shdr = elf64_getshdr (section);
+    assert (shdr);
+    const char *t = string_table + shdr->sh_name;

No declarations after code.


+/* Parse an entry of the IL symbol table. The data to be parsed is pointed
+   by P and the result is written in ENTRY. Returs the address of the next
+   entry. */

s/Returs/Returns/


All the functions above would go into liblto. Initially, we would not export functions to recreate gimple or symbols, but over time we could move chunks of the streamer into liblto.

Thoughts?


Diego.



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