mirror of
https://github.com/reactos/reactos.git
synced 2024-07-31 00:28:56 +00:00
- Create always the output file. If no debug section exist, do not create a rossym section.
svn path=/trunk/; revision=15436
This commit is contained in:
parent
67c71ced7c
commit
750d4fd13f
|
@ -146,13 +146,20 @@ ConvertStabs(ULONG *SymbolsCount, PROSSYM_ENTRY *SymbolsBase,
|
||||||
|
|
||||||
StabEntry = StabSymbolsBase;
|
StabEntry = StabSymbolsBase;
|
||||||
Count = StabSymbolsLength / sizeof(STAB_ENTRY);
|
Count = StabSymbolsLength / sizeof(STAB_ENTRY);
|
||||||
|
*SymbolsCount = 0;
|
||||||
|
if (Count == 0)
|
||||||
|
{
|
||||||
|
/* No symbol info */
|
||||||
|
*SymbolsBase = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
*SymbolsBase = malloc(Count * sizeof(ROSSYM_ENTRY));
|
*SymbolsBase = malloc(Count * sizeof(ROSSYM_ENTRY));
|
||||||
if (NULL == *SymbolsBase)
|
if (NULL == *SymbolsBase)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to allocate memory for converted .stab symbols\n");
|
fprintf(stderr, "Failed to allocate memory for converted .stab symbols\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
*SymbolsCount = 0;
|
|
||||||
|
|
||||||
LastFunctionAddress = 0;
|
LastFunctionAddress = 0;
|
||||||
First = 1;
|
First = 1;
|
||||||
|
@ -330,13 +337,18 @@ MergeStabsAndCoffs(ULONG *MergedSymbolCount, PROSSYM_ENTRY *MergedSymbols,
|
||||||
ULONG_PTR StabFunctionStartAddress;
|
ULONG_PTR StabFunctionStartAddress;
|
||||||
ULONG StabFunctionStringOffset, NewStabFunctionStringOffset;
|
ULONG StabFunctionStringOffset, NewStabFunctionStringOffset;
|
||||||
|
|
||||||
|
*MergedSymbolCount = 0;
|
||||||
|
if (StabSymbolsCount == 0)
|
||||||
|
{
|
||||||
|
*MergedSymbols = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
*MergedSymbols = malloc(StabSymbolsCount * sizeof(ROSSYM_ENTRY));
|
*MergedSymbols = malloc(StabSymbolsCount * sizeof(ROSSYM_ENTRY));
|
||||||
if (NULL == *MergedSymbols)
|
if (NULL == *MergedSymbols)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to allocate memory for merged symbols\n");
|
fprintf(stderr, "Unable to allocate memory for merged symbols\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
*MergedSymbolCount = 0;
|
|
||||||
|
|
||||||
StabFunctionStartAddress = 0;
|
StabFunctionStartAddress = 0;
|
||||||
StabFunctionStringOffset = 0;
|
StabFunctionStringOffset = 0;
|
||||||
|
@ -627,32 +639,38 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
OutOptHeader->FileAlignment);
|
OutOptHeader->FileAlignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
RosSymFileLength = ROUND_UP(RosSymLength, OutOptHeader->FileAlignment);
|
if (RosSymLength > 0)
|
||||||
memcpy(CurrentSectionHeader->Name, ".rossym", 8); /* We're lucky: string is exactly 8 bytes long */
|
|
||||||
CurrentSectionHeader->Misc.VirtualSize = RosSymLength;
|
|
||||||
CurrentSectionHeader->VirtualAddress = OutOptHeader->SizeOfImage;
|
|
||||||
CurrentSectionHeader->SizeOfRawData = RosSymFileLength;
|
|
||||||
CurrentSectionHeader->PointerToRawData = RosSymOffset;
|
|
||||||
CurrentSectionHeader->PointerToRelocations = 0;
|
|
||||||
CurrentSectionHeader->PointerToLinenumbers = 0;
|
|
||||||
CurrentSectionHeader->NumberOfRelocations = 0;
|
|
||||||
CurrentSectionHeader->NumberOfLinenumbers = 0;
|
|
||||||
CurrentSectionHeader->Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
|
|
||||||
| IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_TYPE_NOLOAD;
|
|
||||||
OutOptHeader->SizeOfImage = ROUND_UP(CurrentSectionHeader->VirtualAddress +
|
|
||||||
CurrentSectionHeader->Misc.VirtualSize,
|
|
||||||
OutOptHeader->SectionAlignment);
|
|
||||||
(OutFileHeader->NumberOfSections)++;
|
|
||||||
|
|
||||||
PaddedRosSym = malloc(RosSymFileLength);
|
|
||||||
if (NULL == PaddedRosSym)
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to allocate %lu bytes for padded .rossym\n", RosSymFileLength);
|
RosSymFileLength = ROUND_UP(RosSymLength, OutOptHeader->FileAlignment);
|
||||||
return 1;
|
memcpy(CurrentSectionHeader->Name, ".rossym", 8); /* We're lucky: string is exactly 8 bytes long */
|
||||||
}
|
CurrentSectionHeader->Misc.VirtualSize = RosSymLength;
|
||||||
memcpy(PaddedRosSym, RosSymSection, RosSymLength);
|
CurrentSectionHeader->VirtualAddress = OutOptHeader->SizeOfImage;
|
||||||
memset((char *) PaddedRosSym + RosSymLength, '\0', RosSymFileLength - RosSymLength);
|
CurrentSectionHeader->SizeOfRawData = RosSymFileLength;
|
||||||
|
CurrentSectionHeader->PointerToRawData = RosSymOffset;
|
||||||
|
CurrentSectionHeader->PointerToRelocations = 0;
|
||||||
|
CurrentSectionHeader->PointerToLinenumbers = 0;
|
||||||
|
CurrentSectionHeader->NumberOfRelocations = 0;
|
||||||
|
CurrentSectionHeader->NumberOfLinenumbers = 0;
|
||||||
|
CurrentSectionHeader->Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
|
||||||
|
| IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_TYPE_NOLOAD;
|
||||||
|
OutOptHeader->SizeOfImage = ROUND_UP(CurrentSectionHeader->VirtualAddress +
|
||||||
|
CurrentSectionHeader->Misc.VirtualSize,
|
||||||
|
OutOptHeader->SectionAlignment);
|
||||||
|
(OutFileHeader->NumberOfSections)++;
|
||||||
|
|
||||||
|
PaddedRosSym = malloc(RosSymFileLength);
|
||||||
|
if (NULL == PaddedRosSym)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Failed to allocate %lu bytes for padded .rossym\n", RosSymFileLength);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
memcpy(PaddedRosSym, RosSymSection, RosSymLength);
|
||||||
|
memset((char *) PaddedRosSym + RosSymLength, '\0', RosSymFileLength - RosSymLength);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PaddedRosSym = NULL;
|
||||||
|
}
|
||||||
CheckSum = 0;
|
CheckSum = 0;
|
||||||
for (i = 0; i < StartOfRawData / 2; i++)
|
for (i = 0; i < StartOfRawData / 2; i++)
|
||||||
{
|
{
|
||||||
|
@ -666,7 +684,7 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
{
|
{
|
||||||
Data = (void *) ProcessedRelocs;
|
Data = (void *) ProcessedRelocs;
|
||||||
}
|
}
|
||||||
else if (Section + 1 == OutFileHeader->NumberOfSections)
|
else if (RosSymLength > 0 && Section + 1 == OutFileHeader->NumberOfSections)
|
||||||
{
|
{
|
||||||
Data = (void *) PaddedRosSym;
|
Data = (void *) PaddedRosSym;
|
||||||
}
|
}
|
||||||
|
@ -700,7 +718,7 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
{
|
{
|
||||||
Data = (void *) ProcessedRelocs;
|
Data = (void *) ProcessedRelocs;
|
||||||
}
|
}
|
||||||
else if (Section + 1 == OutFileHeader->NumberOfSections)
|
else if (RosSymLength > 0 && Section + 1 == OutFileHeader->NumberOfSections)
|
||||||
{
|
{
|
||||||
Data = (void *) PaddedRosSym;
|
Data = (void *) PaddedRosSym;
|
||||||
}
|
}
|
||||||
|
@ -719,7 +737,10 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(PaddedRosSym);
|
if (PaddedRosSym)
|
||||||
|
{
|
||||||
|
free(PaddedRosSym);
|
||||||
|
}
|
||||||
free(OutHeader);
|
free(OutHeader);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -800,13 +821,6 @@ int main(int argc, char* argv[])
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StabsLength == 0 || StabStringsLength == 0)
|
|
||||||
{
|
|
||||||
/* no symbol info */
|
|
||||||
free(FileData);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetCoffInfo(FileData, PEFileHeader, PESectionHeaders, &CoffsLength, &CoffBase,
|
if (GetCoffInfo(FileData, PEFileHeader, PESectionHeaders, &CoffsLength, &CoffBase,
|
||||||
&CoffStringsLength, &CoffStringBase))
|
&CoffStringsLength, &CoffStringBase))
|
||||||
{
|
{
|
||||||
|
@ -840,7 +854,10 @@ int main(int argc, char* argv[])
|
||||||
CoffsLength, CoffBase, CoffStringsLength, CoffStringBase,
|
CoffsLength, CoffBase, CoffStringsLength, CoffStringBase,
|
||||||
ImageBase, PEFileHeader, PESectionHeaders))
|
ImageBase, PEFileHeader, PESectionHeaders))
|
||||||
{
|
{
|
||||||
free(StabSymbols);
|
if (StabSymbols)
|
||||||
|
{
|
||||||
|
free(StabSymbols);
|
||||||
|
}
|
||||||
free(StringBase);
|
free(StringBase);
|
||||||
free(FileData);
|
free(FileData);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -850,43 +867,61 @@ int main(int argc, char* argv[])
|
||||||
StabSymbolsCount, StabSymbols,
|
StabSymbolsCount, StabSymbols,
|
||||||
CoffSymbolsCount, CoffSymbols))
|
CoffSymbolsCount, CoffSymbols))
|
||||||
{
|
{
|
||||||
free(CoffSymbols);
|
if (CoffSymbols)
|
||||||
free(StabSymbols);
|
{
|
||||||
|
free(CoffSymbols);
|
||||||
|
}
|
||||||
|
if (StabSymbols)
|
||||||
|
{
|
||||||
|
free(StabSymbols);
|
||||||
|
}
|
||||||
free(StringBase);
|
free(StringBase);
|
||||||
free(FileData);
|
free(FileData);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(CoffSymbols);
|
if (CoffSymbols)
|
||||||
free(StabSymbols);
|
|
||||||
|
|
||||||
RosSymLength = sizeof(SYMBOLFILE_HEADER) + MergedSymbolsCount * sizeof(ROSSYM_ENTRY)
|
|
||||||
+ StringsLength;
|
|
||||||
RosSymSection = malloc(RosSymLength);
|
|
||||||
if (NULL == RosSymSection)
|
|
||||||
{
|
{
|
||||||
free(MergedSymbols);
|
free(CoffSymbols);
|
||||||
free(StringBase);
|
|
||||||
free(FileData);
|
|
||||||
fprintf(stderr, "Unable to allocate memory for .rossym section\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
memset(RosSymSection, '\0', RosSymLength);
|
if (StabSymbols)
|
||||||
|
{
|
||||||
|
free(StabSymbols);
|
||||||
|
}
|
||||||
|
if (MergedSymbolsCount == 0)
|
||||||
|
{
|
||||||
|
RosSymLength = 0;
|
||||||
|
RosSymSection = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RosSymLength = sizeof(SYMBOLFILE_HEADER) + MergedSymbolsCount * sizeof(ROSSYM_ENTRY)
|
||||||
|
+ StringsLength;
|
||||||
|
RosSymSection = malloc(RosSymLength);
|
||||||
|
if (NULL == RosSymSection)
|
||||||
|
{
|
||||||
|
free(MergedSymbols);
|
||||||
|
free(StringBase);
|
||||||
|
free(FileData);
|
||||||
|
fprintf(stderr, "Unable to allocate memory for .rossym section\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
memset(RosSymSection, '\0', RosSymLength);
|
||||||
|
|
||||||
SymbolFileHeader = (PSYMBOLFILE_HEADER) RosSymSection;
|
SymbolFileHeader = (PSYMBOLFILE_HEADER) RosSymSection;
|
||||||
SymbolFileHeader->SymbolsOffset = sizeof(SYMBOLFILE_HEADER);
|
SymbolFileHeader->SymbolsOffset = sizeof(SYMBOLFILE_HEADER);
|
||||||
SymbolFileHeader->SymbolsLength = MergedSymbolsCount * sizeof(ROSSYM_ENTRY);
|
SymbolFileHeader->SymbolsLength = MergedSymbolsCount * sizeof(ROSSYM_ENTRY);
|
||||||
SymbolFileHeader->StringsOffset = SymbolFileHeader->SymbolsOffset + SymbolFileHeader->SymbolsLength;
|
SymbolFileHeader->StringsOffset = SymbolFileHeader->SymbolsOffset + SymbolFileHeader->SymbolsLength;
|
||||||
SymbolFileHeader->StringsLength = StringsLength;
|
SymbolFileHeader->StringsLength = StringsLength;
|
||||||
|
|
||||||
memcpy((char *) RosSymSection + SymbolFileHeader->SymbolsOffset, MergedSymbols,
|
memcpy((char *) RosSymSection + SymbolFileHeader->SymbolsOffset, MergedSymbols,
|
||||||
SymbolFileHeader->SymbolsLength);
|
SymbolFileHeader->SymbolsLength);
|
||||||
memcpy((char *) RosSymSection + SymbolFileHeader->StringsOffset, StringBase,
|
memcpy((char *) RosSymSection + SymbolFileHeader->StringsOffset, StringBase,
|
||||||
SymbolFileHeader->StringsLength);
|
SymbolFileHeader->StringsLength);
|
||||||
|
|
||||||
free(MergedSymbols);
|
free(MergedSymbols);
|
||||||
|
}
|
||||||
free(StringBase);
|
free(StringBase);
|
||||||
|
|
||||||
out = fopen(path2, "wb");
|
out = fopen(path2, "wb");
|
||||||
if (out == NULL)
|
if (out == NULL)
|
||||||
{
|
{
|
||||||
|
@ -900,13 +935,19 @@ int main(int argc, char* argv[])
|
||||||
PESectionHeaders, RosSymLength, RosSymSection))
|
PESectionHeaders, RosSymLength, RosSymSection))
|
||||||
{
|
{
|
||||||
fclose(out);
|
fclose(out);
|
||||||
free(RosSymSection);
|
if (RosSymSection)
|
||||||
|
{
|
||||||
|
free(RosSymSection);
|
||||||
|
}
|
||||||
free(FileData);
|
free(FileData);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(out);
|
fclose(out);
|
||||||
free(RosSymSection);
|
if (RosSymSection)
|
||||||
|
{
|
||||||
|
free(RosSymSection);
|
||||||
|
}
|
||||||
free(FileData);
|
free(FileData);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue