~ubuntu-branches/ubuntu/quantal/lightning-extension/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/build/unix/elfhack/elf.cpp

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-05-21 16:09:39 UTC
  • mfrom: (1.3.1) (25.1.1 precise-security)
  • Revision ID: package-import@ubuntu.com-20120521160939-0702473a46xfq3tl
Tags: 1.5~b2+build1-0ubuntu1
New upstream release from the beta channel (CALENDAR_1_5b2_BUILD1)

Show diffs side-by-side

added added

removed removed

Lines of Context:
265
265
    file.seekg(ehdr->e_phoff);
266
266
    for (int i = 0; i < ehdr->e_phnum; i++) {
267
267
        Elf_Phdr phdr(file, e_ident[EI_CLASS], e_ident[EI_DATA]);
 
268
        if (phdr.p_type == PT_LOAD) {
 
269
            // Default alignment for PT_LOAD on x86-64 prevents elfhack from
 
270
            // doing anything useful. However, the system doesn't actually
 
271
            // require such a big alignment, so in order for elfhack to work
 
272
            // efficiently, reduce alignment when it's originally the default
 
273
            // one.
 
274
            if ((ehdr->e_machine == EM_X86_64) && (phdr.p_align == 0x200000))
 
275
              phdr.p_align = 0x1000;
 
276
        }
268
277
        ElfSegment *segment = new ElfSegment(&phdr);
269
278
        // Some segments aren't entirely filled (if at all) by sections
270
279
        // For those, we use fake sections
503
512
    if (previous->getType() != SHT_NOBITS)
504
513
        offset += previous->getSize();
505
514
 
 
515
    Elf32_Word align = 0x1000;
 
516
    for (std::vector<ElfSegment *>::iterator seg = segments.begin(); seg != segments.end(); seg++)
 
517
        align = std::max(align, (*seg)->getAlign());
 
518
 
 
519
    Elf32_Word mask = align - 1;
506
520
    // SHF_TLS is used for .tbss which is some kind of special case.
507
521
    if (((getType() != SHT_NOBITS) || (getFlags() & SHF_TLS)) && (getFlags() & SHF_ALLOC)) {
508
 
        if ((getAddr() & 4095) < (offset & 4095))
509
 
            offset = (offset | 4095) + (getAddr() & 4095) + 1;
 
522
        if ((getAddr() & mask) < (offset & mask))
 
523
            offset = (offset | mask) + (getAddr() & mask) + 1;
510
524
        else
511
 
            offset = (offset & ~4095) + (getAddr() & 4095);
 
525
            offset = (offset & ~mask) + (getAddr() & mask);
512
526
    }
513
527
    if ((getType() != SHT_NOBITS) && (offset & (getAddrAlign() - 1)))
514
528
        offset = (offset | (getAddrAlign() - 1)) + 1;
632
646
    phdr.p_vaddr = 0;
633
647
    phdr.p_paddr = phdr.p_vaddr + v_p_diff;
634
648
    phdr.p_flags = flags;
635
 
    phdr.p_align = 0x1000;
 
649
    phdr.p_align = getAlign();
636
650
    phdr.p_filesz = (unsigned int)-1;
637
651
    phdr.p_memsz = (unsigned int)-1;
638
652
    ElfSegment *segment = new ElfSegment(&phdr);