History

.gnu.linkonce section support (useful to link with recent glibc)

bellard committed 23 years ago

Commit 46169b91 parent d369a771 file · +28 −3Browse files

Unified · Split

tccelf.c+28−3
@@ -1508,7 +1508,8 @@ static void *load_data(int fd, unsigned long file_offset, unsigned long size) · 1507 unmodified lines
15081508 typedef struct SectionMergeInfo {
15091509 Section *s; /* corresponding existing section */
15101510 unsigned long offset; /* offset of the new section in the existing section */
1511− int new_section; /* true if section 's' was added */
1511+ uint8_t new_section; /* true if section 's' was added */
1512+ uint8_t link_once; /* true if link once section */
15121513 } SectionMergeInfo;
15131514
15141515 /* load an object file and merge it with current files */
@@ -1595,8 +1596,19 @@ static int tcc_load_object_file(TCCState *s1, · 80 unmodified lines
15951596 /* find corresponding section, if any */
15961597 for(j = 1; j < s1->nb_sections;j++) {
15971598 s = s1->sections[j];
1598− if (!strcmp(s->name, sh_name))
1599− goto found;
1599+ if (!strcmp(s->name, sh_name)) {
1600+ if (!strncmp(sh_name, ".gnu.linkonce",
1601+ sizeof(".gnu.linkonce") - 1)) {
1602+ /* if a 'linkonce' section is already present, we
1603+ do not add it again. It is a little tricky as
1604+ symbols can still be defined in
1605+ it. */
1606+ sm_table[i].link_once = 1;
1607+ goto next;
1608+ } else {
1609+ goto found;
1610+ }
1611+ }
16001612 }
16011613 /* not found: create new section */
16021614 s = new_section(s1, sh_name, sh->sh_type, sh->sh_flags);
@@ -1630,6 +1642,7 @@ static int tcc_load_object_file(TCCState *s1, · 27 unmodified lines
16301642 } else {
16311643 s->data_offset += size;
16321644 }
1645+ next: ;
16331646 }
16341647
16351648 /* second short pass to update sh_link and sh_info fields of new
@@ -1657,6 +1670,18 @@ static int tcc_load_object_file(TCCState *s1, · 21 unmodified lines
16571670 if (sym->st_shndx != SHN_UNDEF &&
16581671 sym->st_shndx < SHN_LORESERVE) {
16591672 sm = &sm_table[sym->st_shndx];
1673+ if (sm->link_once) {
1674+ /* if a symbol is in a link once section, we use the
1675+ already defined symbol. It is very important to get
1676+ correct relocations */
1677+ if (ELF32_ST_BIND(sym->st_info) != STB_LOCAL) {
1678+ name = strtab + sym->st_name;
1679+ sym_index = find_elf_sym(symtab_section, name);
1680+ if (sym_index)
1681+ old_to_new_syms[i] = sym_index;
1682+ }
1683+ continue;
1684+ }
16601685 /* if no corresponding section added, no need to add symbol */
16611686 if (!sm->s)
16621687 continue;

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