History

Link alias symbols together

Make sure alias symbols resolve to the same address in program .bss or .data section. This ensure for example that if a program reference environ (via an extern char **environ declaration) and the libc change its value via the __environ alias after the R_ARCH_COPY relocation have been performed, then the program will see the new value.

Thomas Preud'homme committed 16 years ago

Commit a28b18f1 parent 036ff171 file · +20 −0Browse files

Unified · Split

tccelf.c+20−0
@@ -1510,12 +1510,32 @@ static int elf_output_file(TCCState *s1, const char *filename) · 1509 unmodified lines
15101510 sym - (ElfW(Sym) *)symtab_section->data);
15111511 } else if (type == STT_OBJECT) {
15121512 unsigned long offset;
1513+ ElfW(Sym) *dynsym, *dynsym_end;
15131514 offset = bss_section->data_offset;
15141515 /* XXX: which alignment ? */
15151516 offset = (offset + 16 - 1) & -16;
15161517 index = put_elf_sym(s1->dynsym, offset, esym->st_size,
15171518 esym->st_info, 0,
15181519 bss_section->sh_num, name);
1520+ /* Ensure symbol aliases (that is, symbols with
1521+ the same st_value) resolve to the same
1522+ address in program .bss or .data section. */
1523+ dynsym_end = (ElfW(Sym) *)
1524+ (s1->dynsymtab_section->data +
1525+ s1->dynsymtab_section->data_offset);
1526+ for(dynsym = (ElfW(Sym) *)s1->dynsymtab_section->data + 1;
1527+ dynsym < dynsym_end; dynsym++) {
1528+ if (dynsym->st_value == esym->st_value) {
1529+ char *dynname;
1530+ dynname = s1->dynsymtab_section->link->data
1531+ + dynsym->st_name;
1532+ put_elf_sym(s1->dynsym, offset,
1533+ dynsym->st_size,
1534+ dynsym->st_info, 0,
1535+ bss_section->sh_num,
1536+ dynname);
1537+ }
1538+ }
15191539 put_elf_reloc(s1->dynsym, bss_section,
15201540 offset, R_COPY, index);
15211541 offset += esym->st_size;

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