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
3037 return b[3] | (b[2] << 8) | (b[1] << 16) | (b[0] << 24);3037 return b[3] | (b[2] << 8) | (b[1] << 16) | (b[0] << 24);
3038}3038}
3039 3039
3040static 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
3040/* load only the objects which resolve undefined symbols */3047/* load only the objects which resolve undefined symbols */
3041static int tcc_load_alacarte(TCCState *s1, int fd, int size)3048static int tcc_load_alacarte(TCCState *s1, int fd, int size, int entrysize)
3042{3049{
3043 int i, bound, nsyms, sym_index, off, ret;3050 long i, bound, nsyms, sym_index, off, ret;
3044 uint8_t *data;3051 uint8_t *data;
3045 const char *ar_names, *p;3052 const char *ar_names, *p;
3046 const uint8_t *ar_index;3053 const uint8_t *ar_index;
@@ -3049,9 +3056,9 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 2 unmodified lines
3049 data = tcc_malloc(size);3056 data = tcc_malloc(size);
3050 if (read(fd, data, size) != size)3057 if (read(fd, data, size) != size)
3051 goto fail;3058 goto fail;
3052 nsyms = get_be32(data);3059 nsyms = entrysize == 4 ? get_be32(data) : get_be64(data);
3053 ar_index = data + 4;3060 ar_index = data + entrysize;
3054 ar_names = (char *) ar_index + nsyms * 4;3061 ar_names = (char *) ar_index + nsyms * entrysize;
3055 3062
3056 do {3063 do {
3057 bound = 0;3064 bound = 0;
@@ -3060,7 +3067,10 @@ static int tcc_load_alacarte(TCCState *s1, int fd, int size) · 2 unmodified lines
3060 if(sym_index) {3067 if(sym_index) {
3061 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];3068 sym = &((ElfW(Sym) *)symtab_section->data)[sym_index];
3062 if(sym->st_shndx == SHN_UNDEF) {3069 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);
3064 ++bound;3074 ++bound;
3065 if(tcc_load_object_file(s1, fd, off) < 0) {3075 if(tcc_load_object_file(s1, fd, off) < 0) {
3066 fail:3076 fail:
@@ -3113,7 +3123,10 @@ ST_FUNC int tcc_load_archive(TCCState *s1, int fd) · 46 unmodified lines
3113 if (!strcmp(ar_name, "/")) {3123 if (!strcmp(ar_name, "/")) {
3114 /* coff symbol table : we handle it */3124 /* coff symbol table : we handle it */
3115 if(s1->alacarte_link)3125 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);
3117 } else {3130 } else {
3118 ElfW(Ehdr) ehdr;3131 ElfW(Ehdr) ehdr;
3119 if (tcc_object_type(fd, &ehdr) == AFF_BINTYPE_REL) {3132 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