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
1508typedef struct SectionMergeInfo {1508typedef struct SectionMergeInfo {
1509 Section *s; /* corresponding existing section */1509 Section *s; /* corresponding existing section */
1510 unsigned long offset; /* offset of the new section in the existing section */1510 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 */
1512} SectionMergeInfo;1513} SectionMergeInfo;
1513 1514
1514/* load an object file and merge it with current files */1515/* 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
1595 /* find corresponding section, if any */1596 /* find corresponding section, if any */
1596 for(j = 1; j < s1->nb_sections;j++) {1597 for(j = 1; j < s1->nb_sections;j++) {
1597 s = s1->sections[j];1598 s = s1->sections[j];
1598 if (!strcmp(s->name, sh_name))1599 if (!strcmp(s->name, sh_name)) {
1599 goto found;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 }
1600 }1612 }
1601 /* not found: create new section */1613 /* not found: create new section */
1602 s = new_section(s1, sh_name, sh->sh_type, sh->sh_flags);1614 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
1630 } else {1642 } else {
1631 s->data_offset += size;1643 s->data_offset += size;
1632 }1644 }
1645 next: ;
1633 }1646 }
1634 1647
1635 /* second short pass to update sh_link and sh_info fields of new1648 /* 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
1657 if (sym->st_shndx != SHN_UNDEF &&1670 if (sym->st_shndx != SHN_UNDEF &&
1658 sym->st_shndx < SHN_LORESERVE) {1671 sym->st_shndx < SHN_LORESERVE) {
1659 sm = &sm_table[sym->st_shndx];1672 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 }
1660 /* if no corresponding section added, no need to add symbol */1685 /* if no corresponding section added, no need to add symbol */
1661 if (!sm->s)1686 if (!sm->s)
1662 continue;1687 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