]> git.enpas.org Git - centaur.git/blobdiff - src/libelfu/model/symtab.c
GPLv2 release
[centaur.git] / src / libelfu / model / symtab.c
index 0cf107be0fadcffb31ed376e00983ff706236453..2b70e6ed546b9e6de9d141dcd161e4287d662794 100644 (file)
@@ -1,3 +1,18 @@
+/* This file is part of centaur.
+ *
+ * centaur is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License 2 as
+ * published by the Free Software Foundation.
+
+ * centaur is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with centaur.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
@@ -198,3 +213,48 @@ void elfu_mSymtabFlatten(ElfuElf *me)
 
   elfu_mLayoutAuto(me);
 }
+
+
+
+void elfu_mSymtabAddGlobalDymtabIfNotPresent(ElfuElf *me)
+{
+  assert(me);
+
+  if (!me->symtab) {
+    ElfuScn *symtab;
+    ElfuScn *strtab;
+
+    symtab = elfu_mScnAlloc();
+    assert(symtab);
+    strtab = elfu_mScnAlloc();
+    assert(strtab);
+
+    symtab->linkptr = strtab;
+    symtab->shdr.sh_entsize = me->elfclass == ELFCLASS32 ? sizeof(Elf32_Sym) : sizeof(Elf64_Sym);
+    symtab->shdr.sh_addralign = 4;
+    strtab->shdr.sh_addralign = 1;
+    symtab->shdr.sh_type = SHT_SYMTAB;
+    strtab->shdr.sh_type = SHT_STRTAB;
+
+    strtab->databuf = malloc(1);
+    assert(strtab->databuf);
+    strtab->databuf[0] = 0;
+
+    CIRCLEQ_INSERT_TAIL(&me->orphanScnList, symtab, elemChildScn);
+    CIRCLEQ_INSERT_TAIL(&me->orphanScnList, strtab, elemChildScn);
+
+    me->symtab = symtab;
+
+    if (me->shstrtab) {
+      symtab->shdr.sh_name = me->shstrtab->shdr.sh_size;
+      if (elfu_mScnAppendData(me->shstrtab, ".symtab", 8)) {
+        symtab->shdr.sh_name = 0;
+      }
+
+      strtab->shdr.sh_name = me->shstrtab->shdr.sh_size;
+      if (elfu_mScnAppendData(me->shstrtab, ".strtab", 8)) {
+        strtab->shdr.sh_name = 0;
+      }
+    }
+  }
+}