ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
May 2007
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
17 participants
322 discussions
Start a n
N
ew thread
[arty] 26605: Don't replace linker name on that pass.
by arty@svn.reactos.org
Author: arty Date: Tue May 1 11:25:44 2007 New Revision: 26605 URL:
http://svn.reactos.org/svn/reactos?rev=26605&view=rev
Log: Don't replace linker name on that pass. Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/compdvr.cpp Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/compdvr.cpp URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/compdvr.cpp (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/compdvr.cpp Tue May 1 11:25:44 2007 @@ -309,7 +309,6 @@ if( subcmd_args[0].find("collect2") != std::string::npos || subcmd_args[0].find("ld") != std::string::npos ) { - subcmd_args[0] = linker_name; if( status = run_ld( verbose, nostdlib, nostartfiles, is_dll, make_map, mingw_lib_dir, ldscript, subcmd_args ) )
17 years, 7 months
1
0
0
0
[arty] 26604: Final commits for elf conversion.
by arty@svn.reactos.org
Author: arty Date: Tue May 1 11:20:45 2007 New Revision: 26604 URL:
http://svn.reactos.org/svn/reactos?rev=26604&view=rev
Log: Final commits for elf conversion. Modified: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_vga.c branches/powerpc/reactos/tools/ppc-build/elfpe/compdvr.cpp branches/powerpc/reactos/tools/ppc-build/elfpe/header.cpp branches/powerpc/reactos/tools/ppc-build/elfpe/header.h branches/powerpc/reactos/tools/ppc-build/elfpe/objectfile.cpp branches/powerpc/reactos/tools/ppc-build/elfpe/objectfile.h branches/powerpc/reactos/tools/ppc-build/elfpe/pedef.h branches/powerpc/reactos/tools/ppc-build/elfpe/util.cpp branches/powerpc/reactos/tools/ppc-build/elfpe/util.h Modified: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fr…
============================================================================== --- branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c (original) +++ branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/mboot.c Tue May 1 11:20:45 2007 @@ -398,6 +398,9 @@ * MemLoadAddr -- Freeldr address of module * KernelAddr -- Kernel address of module *--*/ +#define ELF_SECTION(n) ((Elf32_Shdr*)(sptr + (n * shsize))) +#define COFF_FIRST_SECTION(h) ((PIMAGE_SECTION_HEADER) ((DWORD)h+FIELD_OFFSET(IMAGE_NT_HEADERS,OptionalHeader)+(SWAPW(((PIMAGE_NT_HEADERS)(h))->FileHeader.SizeOfOptionalHeader)))) + BOOLEAN NTAPI FrLdrMapModule(FILE *KernelImage, PCHAR ImageName, PCHAR MemLoadAddr, ULONG KernelAddr) @@ -410,7 +413,6 @@ INT i, j; PLOADER_MODULE ModuleData; int phsize, phnum, shsize, shnum, relsize, SectionAddr = 0; - PULONG SectionOffsets; PCHAR sptr; Elf32_Ehdr ehdr; Elf32_Shdr *shdr; @@ -441,7 +443,6 @@ shsize = ehdr.e_shentsize; shnum = ehdr.e_shnum; sptr = (PCHAR)MmAllocateMemory(shnum * shsize); - SectionOffsets = (PULONG)MmAllocateMemory(shnum * sizeof(ULONG)); /* Read section headers */ FsSetFilePointer(KernelImage, ehdr.e_shoff); @@ -452,8 +453,8 @@ /* Now we'll get the PE Header */ for( i = 0; i < shnum; i++ ) { - shdr = (Elf32_Shdr*)(sptr + (i * shsize)); - printf("Header %d: type %d flags %x\n", i, shdr->sh_type, shdr->sh_flags); + shdr = ELF_SECTION(i); + /* Find the PE Header */ if (shdr->sh_type == TYPE_PEHEADER) { @@ -462,7 +463,6 @@ ImageHeader = (PIMAGE_DOS_HEADER)KernelMemory; NtHeader = (PIMAGE_NT_HEADERS)((PCHAR)KernelMemory + SWAPD(ImageHeader->e_lfanew)); printf("NtHeader at %x\n", SWAPD(ImageHeader->e_lfanew)); - SectionOffsets[i] = 0; printf("SectionAlignment %x\n", SWAPD(NtHeader->OptionalHeader.SectionAlignment)); SectionAddr = ROUND_UP @@ -478,38 +478,46 @@ return 0; } - /* Save the Image Size */ + /* Save the Image Base */ NtHeader->OptionalHeader.ImageBase = SWAPD(KernelAddr); /* Load the file image */ - Section = IMAGE_FIRST_SECTION(NtHeader); - SectionCount = NtHeader->FileHeader.NumberOfSections - 1; + Section = COFF_FIRST_SECTION(NtHeader); + SectionCount = SWAPW(NtHeader->FileHeader.NumberOfSections); + + printf("Section headers at %x\n", ((PCHAR)Section) - ((PCHAR)KernelAddr)); + + printf("-- Dumping ntoskrnl memory --\n"); + for (i = 0; i < 0x1000; i++) { + if(!(i & 0xf)) { + if(i) printf("\n"); + for (j = 0; j < 8; j++) + printf("%x", (((KernelAddr + i) << (j * 4)) >> 28) & 0xf); + printf(": "); + } + printf("%x%x ", + (*(((PCHAR)KernelMemory)+i)>>4)&0xf, + *(((PCHAR)KernelMemory)+i)&0xf); + } + printf("-- Dump done --\n"); /* Walk each section */ for (i=0; i < SectionCount; i++, Section++) { - shdr = (Elf32_Shdr*)(sptr + (i * shsize)); - if ((shdr->sh_type != SHT_PROGBITS) && - (shdr->sh_type != SHT_NOBITS)) continue; - - SectionOffsets[i] = SectionAddr; + printf("Section %d (NT Header) is elf section %d\n", + i, SWAPD(Section->PointerToRawData)); + shdr = ELF_SECTION(SWAPD(Section->PointerToRawData)); + + shdr->sh_addr = SectionAddr = SWAPD(Section->VirtualAddress); - shdr = (Elf32_Shdr*)(sptr + (i * shsize)); - - /* Get the disk location and the memory location, and the size */ - Section->Misc.VirtualSize = SWAPD(shdr->sh_size); - Section->VirtualAddress = SWAPD(SectionAddr); - Section->SizeOfRawData = SWAPD(shdr->sh_size); - Section->PointerToRawData = SWAPD(shdr->sh_offset); - - if (shdr->sh_type == SHT_PROGBITS) + if (shdr->sh_type != SHT_NOBITS) { /* Content area */ printf("Loading section %d at %x\n", i, KernelAddr + SectionAddr); FsSetFilePointer(KernelImage, shdr->sh_offset); FsReadFile(KernelImage, shdr->sh_size, NULL, KernelMemory + SectionAddr); } - else if (shdr->sh_type == SHT_NOBITS) + else { /* Zero it out */ printf("BSS section %d at %x\n", i, KernelAddr + SectionAddr); @@ -517,18 +525,14 @@ ROUND_UP(shdr->sh_size, SWAPD(NtHeader->OptionalHeader.SectionAlignment))); } - - SectionAddr += - ROUND_UP - (shdr->sh_size, SWAPD(NtHeader->OptionalHeader.SectionAlignment)); - } - - ImageSize = SectionAddr; - NtHeader->OptionalHeader.SizeOfImage = SWAPD(ImageSize); + } + + ImageSize = SWAPD(NtHeader->OptionalHeader.SizeOfImage); + KernelEntry = SWAPD(NtHeader->OptionalHeader.AddressOfEntryPoint); printf("Total image size is %x\n", ImageSize); /* Handle relocation sections */ - for (Section = IMAGE_FIRST_SECTION(NtHeader), i = 0; + for (Section = COFF_FIRST_SECTION(NtHeader), i = 0; i < SectionCount; i++, Section++) { Elf32_Rela reloc = { }; @@ -537,7 +541,7 @@ int numreloc, relstart, targetSection; Elf32_Sym symbol; - shdr = (Elf32_Shdr*)(sptr + (i * shsize)); + shdr = ELF_SECTION(i); /* Only relocs here */ if((shdr->sh_type != SHT_REL) && (shdr->sh_type != SHT_RELA)) continue; @@ -551,12 +555,13 @@ i, shdr->sh_link, shdr->sh_info); /* Get the symbol section */ - shdr = (Elf32_Shdr*)(sptr + (shdr->sh_link * shsize)); + shdr = ELF_SECTION(shdr->sh_link); for(j = 0; j < numreloc; j++) { ULONG S,A,P; + /* Get the reloc */ FsSetFilePointer(KernelImage, relstart + (numreloc * relsize)); FsReadFile(KernelImage, sizeof(reloc), NULL, &reloc); @@ -566,12 +571,12 @@ FsReadFile(KernelImage, sizeof(symbol), NULL, &symbol); /* Compute addends */ - S = symbol.st_value + KernelAddr + SectionOffsets[symbol.st_shndx]; + S = symbol.st_value + KernelAddr + ELF_SECTION(symbol.st_shndx)->sh_addr; A = reloc.r_addend; - P = reloc.r_offset + KernelAddr + SectionOffsets[targetSection]; + P = reloc.r_offset + KernelAddr + ELF_SECTION(targetSection)->sh_addr; Target32 = - (ULONG*)(((PCHAR)KernelMemory) + SectionOffsets[targetSection]); + (ULONG*)(((PCHAR)KernelMemory) + ELF_SECTION(targetSection)->sh_addr); Target16 = (USHORT *)Target32; switch (ELF32_R_TYPE(reloc.r_info)) @@ -603,22 +608,6 @@ } } -#if 0 - printf("-- Dumping ntoskrnl memory --\n"); - for (i = 0; i < ImageSize; i++) { - if(!(i & 0xf)) { - if(i) printf("\n"); - for (j = 0; j < 8; j++) - printf("%x", (((KernelAddr + i) << (j * 4)) >> 28) & 0xf); - printf(": "); - } - printf("%x%x ", - (*(((PCHAR)KernelMemory)+i)>>4)&0xf, - *(((PCHAR)KernelMemory)+i)&0xf); - } - printf("-- Dump done --\n"); -#endif - ModuleData = &reactos_modules[LoaderBlock.ModsCount]; ModuleData->ModStart = (ULONG)KernelMemory; /* Increase the next Load Base */ Modified: branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_vga.c URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/boot/freeldr/fr…
============================================================================== --- branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_vga.c (original) +++ branches/powerpc/reactos/boot/freeldr/freeldr/arch/powerpc/prep_vga.c Tue May 1 11:20:45 2007 @@ -1,5 +1,8 @@ #include <freeldr.h> #include "prep.h" +#include "ppcboot.h" + +extern boot_infos_t BootInfo; struct _vga_desc { char *port; @@ -20,6 +23,7 @@ print_bar( &bar_data ); if( (bar_data.data > 0x10000) || ((bar_data.data&1) == 1) ) { vga_desc->addr = (char *)(0xc0000000 + (bar_data.data & ~0x7ff)); + BootInfo.dispDeviceBase = vga_desc->addr; break; } } Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/compdvr.cpp URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/compdvr.cpp (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/compdvr.cpp Tue May 1 11:20:45 2007 @@ -127,11 +127,12 @@ bool use_libgcc = false; std::vector<std::string> args = arg_vect; std::string real_output, - entry_point = "0x1000", + entry_point = "_main", image_base = "0x400000", subsystem = "windows", make_dll, file_align = "0x1000", section_align = "0x1000", base_file; + const ElfObjectFile::Symbol *entry_sym; std::vector<std::string>::iterator i = std::find(args.begin(),args.end(),"-lgcc"); @@ -163,8 +164,6 @@ args.insert(args.begin()+1,"-T"); args.insert(args.begin()+2,ldscript); args.insert(args.begin()+1,"-r"); - args.insert(args.begin()+1,"--start-group"); - args.push_back("--end-group"); for( size_t i = 0; i < args.size(); i++ ) { if( args[i] == "-o" && i < args.size()-1 ) { @@ -201,16 +200,19 @@ if(!eof) return 1; + entry_sym = eof.getNamedSymbol(entry_point); + ElfPeHeader header (strtoul(image_base.c_str(), 0, 0), strtoul(section_align.c_str(), 0, 0), strtoul(file_align.c_str(), 0, 0), + entry_sym, 0x10000, 0x100000, 0x10000, 0x100000, + atoi(subsystem.c_str()), is_dll, - atoi(subsystem.c_str()), &eof); eof.addSection(".peheader", header.getData(), TYPE_PEHEADER); @@ -307,7 +309,9 @@ if( subcmd_args[0].find("collect2") != std::string::npos || subcmd_args[0].find("ld") != std::string::npos ) { - if( run_ld( verbose, nostdlib, nostartfiles, is_dll, make_map, + subcmd_args[0] = linker_name; + if( status = + run_ld( verbose, nostdlib, nostartfiles, is_dll, make_map, mingw_lib_dir, ldscript, subcmd_args ) ) goto final; else @@ -317,7 +321,7 @@ if( verbose ) subcmd_args.insert(subcmd_args.begin()+1,"-v"); - if( execute_command + if( status = execute_command ( verbose, subcmd_args ) ) goto final; } else if( verbose ) @@ -326,7 +330,6 @@ goto theend; final: - status = 1; theend: if( verbose ) { fprintf( stderr, "<status>%d</status>\n", status ); Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/header.cpp URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/header.cpp (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/header.cpp Tue May 1 11:20:45 2007 @@ -6,6 +6,7 @@ (uint32_t imagebase, uint32_t filealign, uint32_t sectionalign, + const ElfObjectFile::Symbol *entry, uint32_t stackreserve, uint32_t stackcommit, uint32_t heapreserve, @@ -20,6 +21,7 @@ heapreserve(heapreserve), heapcommit(heapcommit), subsysid(subsysid), + entry(entry), eof(eof) { data.resize(computeSize()); @@ -33,6 +35,9 @@ void ElfPeHeader::createHeaderSection() { + std::vector<section_mapping_t> sectionRvaSet; + uint32_t imageSize = getSectionRvas(sectionRvaSet); + data[0] = 'M'; data[1] = 'Z'; uint8_t *dataptr = &data[0x3c]; uint32_t coffHeaderSize, optHeaderSizeMember; @@ -40,7 +45,7 @@ dataptr = &data[0x80]; le32write_postinc(dataptr, 0x4550); le16write_postinc(dataptr, getPeArch()); - le16write_postinc(dataptr, getNumSections()); + le16write_postinc(dataptr, sectionRvaSet.size()); le32write_postinc(dataptr, time(NULL)); le32write_postinc(dataptr, 0); le32write_postinc(dataptr, 0); @@ -53,7 +58,7 @@ le32write_postinc(dataptr, 0); le32write_postinc(dataptr, 0); le32write_postinc(dataptr, 0); - le32write_postinc(dataptr, getEntryPoint()); + le32write_postinc(dataptr, getEntryPoint(sectionRvaSet, entry)); le32write_postinc(dataptr, 0); le32write_postinc(dataptr, 0); le32write_postinc(dataptr, imagebase); @@ -66,7 +71,7 @@ le16write_postinc(dataptr, 4); le16write_postinc(dataptr, 0); le32write_postinc(dataptr, 0); - le32write_postinc(dataptr, getImageSize()); + le32write_postinc(dataptr, imageSize); le32write_postinc(dataptr, computeSize()); le32write_postinc(dataptr, 0); // No checksum yet le16write_postinc(dataptr, subsysid); @@ -92,18 +97,50 @@ le16write (&data[0] + optHeaderSizeMember, (dataptr - &data[0]) - coffHeaderSize); + // Here, we store references to the sections, filling in the RVA and + // size, but leaving out the other info. We write the section name + // truncated into the name field and leave the section id in the + // physical address bit + for (int i = 0; i < sectionRvaSet.size(); i++) + { + section_mapping_t mapping = sectionRvaSet[i]; + const ElfObjectFile::Section *section = mapping.section; + std::string name = section->getName(); + uint32_t size = section->logicalSize(); + uint32_t rva = mapping.rva; + for (int j = 0; j < 8; j++) + { + *dataptr++ = j < name.size() ? name[j] : '\000'; + } + le32write_postinc(dataptr, size); + le32write_postinc(dataptr, rva); + le32write_postinc(dataptr, size); + // Note: we put the index in the offset slot so we can find the + // real offset later in the loader + le32write_postinc(dataptr, sectionRvaSet[i].index); + le32write_postinc(dataptr, 0); + le32write_postinc(dataptr, 0); + le32write_postinc(dataptr, 0); + // XXX Figure out the real flags + le32write_postinc(dataptr, IMAGE_SCN_CNT_CODE); + } } const std::vector<uint8_t> &ElfPeHeader::getData() const { return data; } -uint32_t ElfPeHeader::getImageSize() const -{ - uint32_t start = 0; - uint32_t limit = 0; +uint32_t ElfPeHeader::getSectionRvas(std::vector<section_mapping_t> &rvas) const +{ + uint32_t start = computeSize(); + uint32_t limit = start; for(int i = 0; i < eof->getNumSections(); i++) { { const ElfObjectFile::Section § = eof->getSection(i); - limit = roundup(start + sect.logicalSize(), sectionalign); + if(sect.getType() == SHT_PROGBITS) { + limit = roundup(start + sect.logicalSize(), sectionalign); + fprintf(stderr, "rva[%02d:%s] = (%x %x %d)\n", + rvas.size(), sect.getName().c_str(), §, start, i); + rvas.push_back(section_mapping_t(§, start, i)); + } } start = limit; } @@ -174,3 +211,15 @@ { return std::make_pair(0,0); } + +uint32_t ElfPeHeader::getEntryPoint +(const std::vector<ElfPeHeader::section_mapping_t> &secmap, + const ElfObjectFile::Symbol *entry) const +{ + if(entry == NULL) return computeSize(); + for(int i = 0; i < secmap.size(); i++) { + if(secmap[i].index == entry->section) + return secmap[i].rva + entry->offset; + } + return computeSize(); +} Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/header.h URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/header.h (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/header.h Tue May 1 11:20:45 2007 @@ -13,6 +13,7 @@ (uint32_t imagebase, uint32_t imagealign, uint32_t filealign, + const ElfObjectFile::Symbol *entry, uint32_t stackreserve, uint32_t stackcommit, uint32_t heapreserve, @@ -23,8 +24,21 @@ const ElfObjectFile::secdata_t &getData() const; private: + typedef struct section_mapping_t { + const ElfObjectFile::Section *section; + uint32_t rva; + int index; + + section_mapping_t + (const ElfObjectFile::Section *sect, uint32_t rva, int index) : + section(sect), rva(rva), index(index) { } + section_mapping_t(const section_mapping_t &other) : + section(other.section), rva(other.rva), index(other.index) { } + } section_mapping_t; + void createHeaderSection(); - int getNumSections() const { return eof->getNumSections(); } + uint32_t getSectionRvas(std::vector<section_mapping_t> &rvas) const; + uint32_t getEntryPoint(const std::vector<section_mapping_t> &rvas, const ElfObjectFile::Symbol *entry) const; int computeSize() const; int getExeFlags() const { return 0; } int getDllFlags() const { return dll ? IMAGE_FILE_DLL : 0; } @@ -38,8 +52,6 @@ u32pair_t getDescrInfo() const; u32pair_t getMachInfo() const; u32pair_t getTlsInfo() const; - uint32_t getEntryPoint() const { return eof->getEntryPoint(); } - uint32_t getImageSize() const; uint16_t getPeArch() const; uint32_t saToRva(int section, uint32_t offset) const; uint32_t vaToRva(uint32_t source_addr) const; @@ -50,6 +62,7 @@ heapreserve, heapcommit; bool dll; int subsysid; + const ElfObjectFile::Symbol *entry; ElfObjectFile *eof; std::vector<uint8_t> data; static const char *mzHeader; Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/objectfile.cpp URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/objectfile.cpp (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/objectfile.cpp Tue May 1 11:20:45 2007 @@ -1,11 +1,13 @@ #include <libelf/libelf.h> #include <fcntl.h> +#include "util.h" #include "objectfile.h" ElfObjectFile::ElfObjectFile(const std::string &filename) : fd(-1) { Elf_Scn *s = 0; Elf32_Ehdr *ehdr; + Section *sect; fd = open(filename.c_str(), O_RDWR, 0); if(fd >= 0) { if(elf_version(EV_CURRENT) == EV_NONE) { @@ -21,13 +23,17 @@ shnum = ehdr->e_shnum; phnum = ehdr->e_phnum; shstrndx = ehdr->e_shstrndx; + /* Populate section table */ for(size_t i = 0; i < shnum; i++) { s = elf_nextscn(elfHeader, s); if(!s) break; - sections.push_back(new Section(*this, s)); - fprintf(stderr, "Got section %04d %s\n", i, sections[i]->getName().c_str()); + sect = new Section(*this, s); + sections.push_back(sect); + sections_by_name.insert(std::make_pair(sect->getName(), sect)); } + + populateSymbolTable(); } } @@ -35,6 +41,32 @@ { if(elfHeader) elf_end(elfHeader); if(fd >= 0) close(fd); +} + +void ElfObjectFile::populateSymbolTable() +{ + int i = 0, j; + int type, link, flags, section; + uint32_t offset; + std::string name; + uint8_t *data, *symptr; + Elf32_Sym *sym; + Symbol *ourSym; + + for( i = 0; i < getNumSections(); i++ ) { + type = getSection(i).getType(); + link = getSection(i).getLink(); + if( (type == SHT_SYMTAB) || (type == SHT_DYNSYM) ) { + /* Read a symbol */ + sym = (Elf32_Sym*)getSection(i).getSectionData(); + for (j = 0; j < getSection(i).logicalSize() / sizeof(Elf32_Sym); j++) { + name = elf_strptr(elfHeader, link, sym[j].st_name); + ourSym = new Symbol(name, sym[j].st_value, sym[j].st_shndx, sym[j].st_info); + symbols.push_back(ourSym); + symbols_by_name.insert(std::make_pair(name, ourSym)); + } + } + } } uint32_t ElfObjectFile::getEntryPoint() const @@ -66,7 +98,7 @@ /* Finish the section */ shdr->sh_name = newstrdata->d_off; shdr->sh_type = type; - shdr->sh_flags = 0; + shdr->sh_flags = SHF_ALLOC; shdr->sh_addr = 0; shdr->sh_link = 0; shdr->sh_info = 0; @@ -76,8 +108,18 @@ const ElfObjectFile::Section *ElfObjectFile::getNamedSection(const std::string &name) const { - for(size_t i = 0; i < sections.size(); i++) { - if(sections[i]->getName() == name) return sections[i]; - } - return NULL; + std::map<std::string, const ElfObjectFile::Section *>::const_iterator i = + sections_by_name.find(name); + if(i != sections_by_name.end()) + return i->second; + else return NULL; } + +const ElfObjectFile::Symbol *ElfObjectFile::getNamedSymbol(const std::string &name) const +{ + std::map<std::string, const ElfObjectFile::Symbol *>::const_iterator i = + symbols_by_name.find(name); + if(i != symbols_by_name.end()) + return i->second; + else return NULL; +} Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/objectfile.h URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/objectfile.h (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/objectfile.h Tue May 1 11:20:45 2007 @@ -3,41 +3,83 @@ #include <string> #include <vector> +#include <map> #include <libelf/libelf.h> class ElfObjectFile { public: typedef std::vector<uint8_t> secdata_t; + class Symbol { + public: + Symbol(const std::string &name, uint32_t offset, + int section, int flags) : + name(name), offset(offset), section(section), flags(flags) { } + std::string name; + uint32_t offset; + int section; + int flags; + }; + class Section { public: Section(const Section &other) : - obj(other.obj), section(other.section) { } + obj(other.obj), section(other.section), have_data(false) { + e32shdr = elf32_getshdr(section); + } Section(ElfObjectFile &obj, Elf_Scn *sechdr) : - obj(&obj), section(sechdr) { } + obj(&obj), section(sechdr), have_data(false) { + e32shdr = elf32_getshdr(section); + } Section &operator = (const Section &other) { obj = other.obj; + have_data = false; section = other.section; + e32shdr = other.e32shdr; } operator bool () { return !!section; } std::string getName() const { - Elf32_Shdr *e32shdr = elf32_getshdr(section); return obj->getString(e32shdr->sh_name); } + int getType() const { + return e32shdr->sh_type; + } + + int getLink() const { + return e32shdr->sh_link; + } + + int getInfo() const { + return e32shdr->sh_info; + } + int logicalSize() const { - Elf32_Shdr *e32shdr = elf32_getshdr(section); return e32shdr->sh_size; } uint32_t getStartRva() const { - Elf32_Shdr *e32shdr = elf32_getshdr(section); return e32shdr->sh_addr; + } + + uint32_t getFileOffset() const { + return e32shdr->sh_offset; + } + + uint8_t *getSectionData() const { + if(!have_data) { + data = *elf_getdata(section, NULL); + have_data = true; + } + return (uint8_t *)data.d_buf; } private: const ElfObjectFile *obj; Elf_Scn *section; + Elf32_Shdr *e32shdr; + mutable bool have_data; + mutable Elf_Data data; }; ElfObjectFile(const std::string &filename); @@ -54,6 +96,8 @@ (const std::string &name, const secdata_t &data, int type = SHT_PROGBITS); const Section &getSection(int sect) const { return *sections[sect]; } const Section *getNamedSection(const std::string &name) const; + const Symbol &getSymbol(int n) const { return *symbols[n]; } + const Symbol *getNamedSymbol(const std::string &symname) const; private: int fd; @@ -61,6 +105,11 @@ int shstrndx; Elf *elfHeader; std::vector<Section*> sections; + std::map<std::string, const Section *> sections_by_name; + std::vector<Symbol*> symbols; + std::map<std::string, const Symbol *> symbols_by_name; + + void populateSymbolTable(); }; #endif//COMPDVR_ELFOBJECT_H Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/pedef.h URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/pedef.h (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/pedef.h Tue May 1 11:20:45 2007 @@ -29,4 +29,16 @@ #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000 +#define IMAGE_SCN_CNT_CODE 0x00000020 +#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 +#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080 + +#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 +#define IMAGE_SCN_MEM_NOT_CACHED 0x04000000 +#define IMAGE_SCN_MEM_NOT_PAGED 0x08000000 +#define IMAGE_SCN_MEM_SHARED 0x10000000 +#define IMAGE_SCN_MEM_EXECUTE 0x20000000 +#define IMAGE_SCN_MEM_READ 0x40000000 +#define IMAGE_SCN_MEM_WRITE 0x80000000 + #endif//COMPDVR_PEDEF_H Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/util.cpp URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/util.cpp (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/util.cpp Tue May 1 11:20:45 2007 @@ -33,3 +33,27 @@ le32write_postinc(dataptr, value.first); le32write_postinc(dataptr, value.second); } + +uint16_t be16read(uint8_t *dataptr) +{ + return dataptr[0] << 8 | dataptr[1]; +} + +uint16_t be16read_postinc(uint8_t *&dataptr) +{ + uint16_t res = be16read(dataptr); + dataptr += 2; + return res; +} + +uint32_t be32read(uint8_t *dataptr) +{ + return be16read(dataptr) << 16 | be16read(dataptr+2); +} + +uint32_t be32read_postinc(uint8_t *&dataptr) +{ + uint32_t res = be32read(dataptr); + dataptr += 4; + return res; +} Modified: branches/powerpc/reactos/tools/ppc-build/elfpe/util.h URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/ppc-build…
============================================================================== --- branches/powerpc/reactos/tools/ppc-build/elfpe/util.h (original) +++ branches/powerpc/reactos/tools/ppc-build/elfpe/util.h Tue May 1 11:20:45 2007 @@ -12,6 +12,10 @@ uint16_t le16read_postinc(uint8_t *&dataptr); uint32_t le32read(uint8_t *dataptr); uint32_t le32read_postinc(uint8_t *&dataptr); +uint16_t be16read(uint8_t *dataptr); +uint16_t be16read_postinc(uint8_t *&dataptr); +uint32_t be32read(uint8_t *dataptr); +uint32_t be32read_postinc(uint8_t *&dataptr); typedef std::pair<uint32_t, uint32_t> u32pair_t; void le32pwrite_postinc(uint8_t *&dataptr, const u32pair_t &pair); void le32pwrite(uint8_t *dataptr, const u32pair_t &pair);
17 years, 7 months
1
0
0
0
← Newer
1
...
30
31
32
33
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Results per page:
10
25
50
100
200