History

Support archives with 64 bit indices

Some systems started using SYM64 .a libraries, so start supporting them.

Michael Matz committed 10 years ago

Commit c232af71 parent ed15cdd1 file · +20 −7Browse files

Unified · Split

tccelf.c+20−7
@@ -3037,10 +3037,17 @@ static int get_be32(const uint8_t *b) · 3036 unmodified lines
30373037 return b[3] | (b[2] << 8) | (b[1] << 16) | (b[0] << 24);
30383038 }
30393039
3040+static long get_be64(const uint8_t *b)
3041+{
3042+ long long ret = get_be32(b);
3043+ ret = (ret << 32) | (unsigned)get_be32(b+4);
3044+ return (long)ret;
3045+}
3046+
30403047 /* load only the objects which resolve undefined symbols */
3041−static int tcc_load_alacarte(TCCState *s1, int fd, int size)
3048+static int tcc_load_alacarte(TCCState *s1, int fd, int size, int entrysize)
30423049 {
3043− int i, bound, nsyms, sym_index, off, ret;
3050+ long i, bound, nsyms, sym_index, off, ret;
30443051 uint8_t *data;
30453052 const char *ar_names, *p;
30463053 const uint8_t *ar_index;
@@ -3049,9 +3056,9 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 2 unmodified lines
30493056 data = tcc_malloc(size);
30503057 if (read(fd, data, size) != size)
30513058 goto fail;
3052− nsyms = get_be32(data);
3053− ar_index = data + 4;
3054− ar_names = (char *) ar_index + nsyms * 4;
3059+ nsyms = entrysize == 4 ? get_be32(data) : get_be64(data);
3060+ ar_index = data + entrysize;
3061+ ar_names = (char *) ar_index + nsyms * entrysize;
30553062
30563063 do {
30573064 bound = 0;
@@ -3060,7 +3067,10 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 2 unmodified lines
30603067 if(sym_index) {
30613068 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
30623069 if(sym->st_shndx == SHN_UNDEF) {
3063− off = get_be32(ar_index + i * 4) + sizeof(ArchiveHeader);
3070+ off = (entrysize == 4
3071+ ? get_be32(ar_index + i * 4)
3072+ : get_be64(ar_index + i * 8))
3073+ + sizeof(ArchiveHeader);
30643074 ++bound;
30653075 if(tcc_load_object_file(s1, fd, off) < 0) {
30663076 fail:
@@ -3113,7 +3123,10 @@ ST_FUNC int tcc_load_archive(TCCState *s1, int fd) · 46 unmodified lines
31133123 if (!strcmp(ar_name, "/")) {
31143124 /* coff symbol table : we handle it */
31153125 if(s1->alacarte_link)
3116− return tcc_load_alacarte(s1, fd, size);
3126+ return tcc_load_alacarte(s1, fd, size, 4);
3127+ } else if (!strcmp(ar_name, "/SYM64/")) {
3128+ if(s1->alacarte_link)
3129+ return tcc_load_alacarte(s1, fd, size, 8);
31173130 } else {
31183131 ElfW(Ehdr) ehdr;
31193132 if (tcc_object_type(fd, &ehdr) == AFF_BINTYPE_REL) {

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