~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/ld/ldpe.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
{
136
136
        char *name;
137
137
        int32 base;
138
 
        int i, j, l, numaux;
 
138
        uint32 l;
 
139
        int i, j, numaux;
139
140
        PeObj *obj;
140
141
        PeSect *sect, *rsect;
141
142
        IMAGE_SECTION_HEADER sh;
145
146
        PeSym *sym;
146
147
 
147
148
        USED(len);
148
 
        USED(pkg);
149
149
        if(debug['v'])
150
150
                Bprint(&bso, "%5.2f ldpe %s\n", cputime(), pn);
151
151
        
171
171
                // TODO return error if found .cormeta
172
172
        }
173
173
        // load string table
174
 
        Bseek(f, base+obj->fh.PointerToSymbolTable+18*obj->fh.NumberOfSymbols, 0);
175
 
        if(Bread(f, &l, sizeof l) != sizeof l) 
 
174
        Bseek(f, base+obj->fh.PointerToSymbolTable+sizeof(symbuf)*obj->fh.NumberOfSymbols, 0);
 
175
        if(Bread(f, symbuf, 4) != 4) 
176
176
                goto bad;
 
177
        l = le32(symbuf);
177
178
        obj->snames = mal(l);
178
 
        Bseek(f, base+obj->fh.PointerToSymbolTable+18*obj->fh.NumberOfSymbols, 0);
 
179
        Bseek(f, base+obj->fh.PointerToSymbolTable+sizeof(symbuf)*obj->fh.NumberOfSymbols, 0);
179
180
        if(Bread(f, obj->snames, l) != l)
180
181
                goto bad;
181
182
        // read symbols
210
211
                sect = &obj->sect[i];
211
212
                if(sect->sh.Characteristics&IMAGE_SCN_MEM_DISCARDABLE)
212
213
                        continue;
 
214
 
 
215
                if((sect->sh.Characteristics&(IMAGE_SCN_CNT_CODE|IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_CNT_UNINITIALIZED_DATA)) == 0) {
 
216
                        // This has been seen for .idata sections, which we
 
217
                        // want to ignore.  See issues 5106 and 5273.
 
218
                        continue;
 
219
                }
 
220
 
213
221
                if(map(obj, sect) < 0)
214
222
                        goto bad;
215
223
                
216
 
                name = smprint("%s(%s)", pn, sect->name);
 
224
                name = smprint("%s(%s)", pkg, sect->name);
217
225
                s = lookup(name, version);
218
226
                free(name);
219
227
                switch(sect->sh.Characteristics&(IMAGE_SCN_CNT_UNINITIALIZED_DATA|IMAGE_SCN_CNT_INITIALIZED_DATA|
231
239
                                s->type = STEXT;
232
240
                                break;
233
241
                        default:
234
 
                                werrstr("unexpected flags for PE section %s", sect->name);
 
242
                                werrstr("unexpected flags %#08ux for PE section %s", sect->sh.Characteristics, sect->name);
235
243
                                goto bad;
236
244
                }
237
245
                s->p = sect->base;
238
246
                s->np = sect->size;
239
247
                s->size = sect->size;
240
 
                if(s->type == STEXT) {
241
 
                        if(etextp)
242
 
                                etextp->next = s;
243
 
                        else
244
 
                                textp = s;
245
 
                        etextp = s;
246
 
                }
247
248
                sect->sym = s;
248
249
                if(strcmp(sect->name, ".rsrc") == 0)
249
250
                        setpersrc(sect->sym);
256
257
                        continue;
257
258
                if(rsect->sh.Characteristics&IMAGE_SCN_MEM_DISCARDABLE)
258
259
                        continue;
 
260
                if((sect->sh.Characteristics&(IMAGE_SCN_CNT_CODE|IMAGE_SCN_CNT_INITIALIZED_DATA|IMAGE_SCN_CNT_UNINITIALIZED_DATA)) == 0) {
 
261
                        // This has been seen for .idata sections, which we
 
262
                        // want to ignore.  See issues 5106 and 5273.
 
263
                        continue;
 
264
                }
259
265
                r = mal(rsect->sh.NumberOfRelocations*sizeof r[0]);
260
266
                Bseek(f, obj->base+rsect->sh.PointerToRelocations, 0);
261
267
                for(j=0; j<rsect->sh.NumberOfRelocations; j++) {
285
291
                                case IMAGE_REL_AMD64_ADDR32: // R_X86_64_PC32
286
292
                                case IMAGE_REL_AMD64_ADDR32NB:
287
293
                                        rp->type = D_PCREL;
288
 
                                        rp->add = le32(rsect->base+rp->off);
 
294
                                        rp->add = (int32)le32(rsect->base+rp->off);
289
295
                                        break;
290
296
                                case IMAGE_REL_I386_DIR32NB:
291
297
                                case IMAGE_REL_I386_DIR32:
300
306
                                        rp->add = le64(rsect->base+rp->off);
301
307
                                        break;
302
308
                        }
 
309
                        // ld -r could generate multiple section symbols for the
 
310
                        // same section but with different values, we have to take
 
311
                        // that into account
 
312
                        if (obj->pesym[symindex].name[0] == '.')
 
313
                                        rp->add += obj->pesym[symindex].value;
303
314
                }
304
315
                qsort(r, rsect->sh.NumberOfRelocations, sizeof r[0], rbyoff);
305
316
                
341
352
 
342
353
                if(sect == nil) 
343
354
                        return;
 
355
 
 
356
                if(s->outer != S) {
 
357
                        if(s->dupok)
 
358
                                continue;
 
359
                        diag("%s: duplicate symbol reference: %s in both %s and %s", pn, s->name, s->outer->name, sect->sym->name);
 
360
                        errorexit();
 
361
                }
344
362
                s->sub = sect->sym->sub;
345
363
                sect->sym->sub = s;
346
364
                s->type = sect->sym->type | SSUB;
363
381
                        p->link = nil;
364
382
                        p->pc = pc++;
365
383
                        s->text = p;
366
 
        
367
 
                        etextp->next = s;
 
384
                }
 
385
        }
 
386
 
 
387
        // Sort outer lists by address, adding to textp.
 
388
        // This keeps textp in increasing address order.
 
389
        for(i=0; i<obj->nsect; i++) {
 
390
                s = obj->sect[i].sym;
 
391
                if(s == S)
 
392
                        continue;
 
393
                if(s->sub)
 
394
                        s->sub = listsort(s->sub, valuecmp, offsetof(Sym, sub));
 
395
                if(s->type == STEXT) {
 
396
                        if(etextp)
 
397
                                etextp->next = s;
 
398
                        else
 
399
                                textp = s;
368
400
                        etextp = s;
 
401
                        for(s = s->sub; s != S; s = s->sub) {
 
402
                                etextp->next = s;
 
403
                                etextp = s;
 
404
                        }
369
405
                }
370
406
        }
371
407