History

Do not add symbol if it is already there

Do not create a new symbol in add_elf_sym if a symbol with same properties (value, size, info, etc.) already exists. This prevents symbols from being exported twice in the dynamic symbol table.

Thomas Preud'homme committed 10 years ago

Commit e9769a71 parent bf692af1 file · +9 −4Browse files

Unified · Split

tccelf.c+9−4
@@ -394,12 +394,17 @@ ST_FUNC int add_elf_sym(Section *s, addr_t value, unsigned long size, · 393 unmodified lines
394394 sym_type = ELFW(ST_TYPE)(info);
395395 sym_vis = ELFW(ST_VISIBILITY)(other);
396396
397+ sym_index = find_elf_sym(s, name);
398+ esym = &((ElfW(Sym) *)s->data)[sym_index];
399+ if (sym_index && esym->st_value == value && esym->st_size == size
400+ && esym->st_info == info && esym->st_other == other
401+ && esym->st_shndx == sh_num)
402+ return sym_index;
403+
397404 if (sym_bind != STB_LOCAL) {
398405 /* we search global or weak symbols */
399− sym_index = find_elf_sym(s, name);
400406 if (!sym_index)
401407 goto do_def;
402− esym = &((ElfW(Sym) *)s->data)[sym_index];
403408 if (esym->st_shndx != SHN_UNDEF) {
404409 esym_bind = ELFW(ST_BIND)(esym->st_info);
405410 /* propagate the most constraining visibility */
@@ -2058,7 +2063,7 @@ static void bind_exe_dynsyms(TCCState *s1) · 1652 unmodified lines
20582063 } else if (s1->rdynamic && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
20592064 /* if -rdynamic option, then export all non local symbols */
20602065 name = (char *) symtab_section->link->data + sym->st_name;
2061− put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
2066+ add_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
20622067 0, sym->st_shndx, name);
20632068 }
20642069 }
@@ -2081,7 +2086,7 @@ static void bind_libs_dynsyms(TCCState *s1) · 16 unmodified lines
20812086 -rdynamic ? */
20822087 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
20832088 if (sym_index && sym->st_shndx != SHN_UNDEF)
2084− put_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
2089+ add_elf_sym(s1->dynsym, sym->st_value, sym->st_size, sym->st_info,
20852090 0, sym->st_shndx, name);
20862091 else if (esym->st_shndx == SHN_UNDEF) {
20872092 /* weak symbols can stay undefined */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t