Bug 628618 part 5 - Don't set DT_REL*COUNT if it wasn't already set. r=tglek,a=sdwilsh
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 28 Jan 2011 09:22:58 +0100
changeset 61499 839312525a7d8659e3a23ec48845428c2f72272e
parent 61498 b4a47cdebab6446343fcf5cdc4b3df77e840c75d
child 61500 66ebc5e21967bc6500cd6e73f4b7b8b142f5c658
push idunknown
push userunknown
push dateunknown
reviewerstglek, sdwilsh
bugs628618
milestone2.0b11pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 628618 part 5 - Don't set DT_REL*COUNT if it wasn't already set. r=tglek,a=sdwilsh
build/unix/elfhack/elf.cpp
build/unix/elfhack/elfhack.cpp
build/unix/elfhack/elfxx.h
--- a/build/unix/elfhack/elf.cpp
+++ b/build/unix/elfhack/elf.cpp
@@ -614,25 +614,31 @@ ElfSegment *ElfSegment::splitBefore(ElfS
 
     for (rm = i; i != sections.end(); ++i)
         segment->addSection(*i);
     sections.erase(rm, sections.end());
 
     return segment;
 }
 
-ElfSection *ElfDynamic_Section::getSectionForType(unsigned int tag)
+ElfValue *ElfDynamic_Section::getValueForType(unsigned int tag)
 {
     for (unsigned int i = 0; i < shdr.sh_size / shdr.sh_entsize; i++)
         if (dyns[i].tag == tag)
-            return dyns[i].value->getSection();
+            return dyns[i].value;
 
     return NULL;
 }
 
+ElfSection *ElfDynamic_Section::getSectionForType(unsigned int tag)
+{
+    ElfValue *value = getValueForType(tag);
+    return value ? value->getSection() : NULL;
+}
+
 void ElfDynamic_Section::setValueForType(unsigned int tag, ElfValue *val)
 {
     unsigned int i;
     for (i = 0; (i < shdr.sh_size / shdr.sh_entsize) && (dyns[i].tag != DT_NULL); i++)
         if (dyns[i].tag == tag) {
             delete dyns[i].value;
             dyns[i].value = val;
             return;
--- a/build/unix/elfhack/elfhack.cpp
+++ b/build/unix/elfhack/elfhack.cpp
@@ -350,17 +350,18 @@ int do_relocation_section(Elf *elf, unsi
     relhack_entry.r_offset = relhack_entry.r_info = 0;
     relhack->push_back(relhack_entry);
 
     section->rels.assign(new_rels.begin(), new_rels.end());
     section->shrink(new_rels.size() * section->getEntSize());
     ElfLocation *init = new ElfLocation(relhackcode, 0);
     dyn->setValueForType(DT_INIT, init);
     // TODO: adjust the value according to the remaining number of relative relocations
-    dyn->setValueForType(Rel_Type::d_tag_count, new ElfPlainValue(0));
+    if (dyn->getValueForType(Rel_Type::d_tag_count))
+        dyn->setValueForType(Rel_Type::d_tag_count, new ElfPlainValue(0));
     return 0;
 }
 
 static inline int backup_file(const char *name)
 {
     std::string fname(name);
     fname += ".bak";
     return rename(name, fname.c_str());
--- a/build/unix/elfhack/elfxx.h
+++ b/build/unix/elfhack/elfxx.h
@@ -447,16 +447,17 @@ struct Elf_DynValue {
 
 class ElfDynamic_Section: public ElfSection {
 public:
     ElfDynamic_Section(Elf_Shdr &s, std::ifstream *file, Elf *parent);
     ~ElfDynamic_Section();
 
     void serialize(std::ofstream &file, char ei_class, char ei_data);
 
+    ElfValue *getValueForType(unsigned int tag);
     ElfSection *getSectionForType(unsigned int tag);
     void setValueForType(unsigned int tag, ElfValue *val);
 private:
     std::vector<Elf_DynValue> dyns;
 };
 
 typedef serializable<Elf_Sym_Traits> Elf_Sym;