- Create always the output file. If no debug section exist, do not
create a rossym section.
Modified: trunk/reactos/tools/rsym.c
_____
Modified: trunk/reactos/tools/rsym.c
--- trunk/reactos/tools/rsym.c 2005-05-20 15:15:19 UTC (rev 15435)
+++ trunk/reactos/tools/rsym.c 2005-05-20 18:15:44 UTC (rev 15436)
@@ -146,13 +146,20 @@
StabEntry = StabSymbolsBase;
Count = StabSymbolsLength / sizeof(STAB_ENTRY);
+ *SymbolsCount = 0;
+ if (Count == 0)
+ {
+ /* No symbol info */
+ *SymbolsBase = NULL;
+ return 0;
+ }
+
*SymbolsBase = malloc(Count * sizeof(ROSSYM_ENTRY));
if (NULL == *SymbolsBase)
{
fprintf(stderr, "Failed to allocate memory for converted .stab
symbols\n");
return 1;
}
- *SymbolsCount = 0;
LastFunctionAddress = 0;
First = 1;
@@ -330,13 +337,18 @@
ULONG_PTR StabFunctionStartAddress;
ULONG StabFunctionStringOffset, NewStabFunctionStringOffset;
+ *MergedSymbolCount = 0;
+ if (StabSymbolsCount == 0)
+ {
+ *MergedSymbols = NULL;
+ return 0;
+ }
*MergedSymbols = malloc(StabSymbolsCount * sizeof(ROSSYM_ENTRY));
if (NULL == *MergedSymbols)
{
fprintf(stderr, "Unable to allocate memory for merged
symbols\n");
return 1;
}
- *MergedSymbolCount = 0;
StabFunctionStartAddress = 0;
StabFunctionStringOffset = 0;
@@ -627,32 +639,38 @@
OutOptHeader->FileAlignment);
}
- RosSymFileLength = ROUND_UP(RosSymLength,
OutOptHeader->FileAlignment);
- 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,
+ if (RosSymLength > 0)
+ {
+ RosSymFileLength = ROUND_UP(RosSymLength,
OutOptHeader->FileAlignment);
+ 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)++;
+ (OutFileHeader->NumberOfSections)++;
- PaddedRosSym = malloc(RosSymFileLength);
- if (NULL == PaddedRosSym)
+ 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
{
- fprintf(stderr, "Failed to allocate %lu bytes for padded
.rossym\n", RosSymFileLength);
- return 1;
+ PaddedRosSym = NULL;
}
- memcpy(PaddedRosSym, RosSymSection, RosSymLength);
- memset((char *) PaddedRosSym + RosSymLength, '\0', RosSymFileLength -
RosSymLength);
-
CheckSum = 0;
for (i = 0; i < StartOfRawData / 2; i++)
{
@@ -666,7 +684,7 @@
{
Data = (void *) ProcessedRelocs;
}
- else if (Section + 1 == OutFileHeader->NumberOfSections)
+ else if (RosSymLength > 0 && Section + 1 ==
OutFileHeader->NumberOfSections)
{
Data = (void *) PaddedRosSym;
}
@@ -700,7 +718,7 @@
{
Data = (void *) ProcessedRelocs;
}
- else if (Section + 1 == OutFileHeader->NumberOfSections)
+ else if (RosSymLength > 0 && Section + 1 ==
OutFileHeader->NumberOfSections)
{
Data = (void *) PaddedRosSym;
}
@@ -719,7 +737,10 @@
}
}
- free(PaddedRosSym);
+ if (PaddedRosSym)
+ {
+ free(PaddedRosSym);
+ }
free(OutHeader);
return 0;
@@ -800,13 +821,6 @@
exit(1);
}
- if (StabsLength == 0 || StabStringsLength == 0)
- {
- /* no symbol info */
- free(FileData);
- return 0;
- }
-
if (GetCoffInfo(FileData, PEFileHeader, PESectionHeaders,
&CoffsLength, &CoffBase,
&CoffStringsLength, &CoffStringBase))
{
@@ -840,7 +854,10 @@
CoffsLength, CoffBase, CoffStringsLength,
CoffStringBase,
ImageBase, PEFileHeader, PESectionHeaders))
{
- free(StabSymbols);
+ if (StabSymbols)
+ {
+ free(StabSymbols);
+ }
free(StringBase);
free(FileData);
exit(1);
@@ -850,43 +867,61 @@
StabSymbolsCount, StabSymbols,
CoffSymbolsCount, CoffSymbols))
{
- free(CoffSymbols);
- free(StabSymbols);
+ if (CoffSymbols)
+ {
+ free(CoffSymbols);
+ }
+ if (StabSymbols)
+ {
+ free(StabSymbols);
+ }
free(StringBase);
free(FileData);
exit(1);
}
- free(CoffSymbols);
- free(StabSymbols);
-
- RosSymLength = sizeof(SYMBOLFILE_HEADER) + MergedSymbolsCount *
sizeof(ROSSYM_ENTRY)
- + StringsLength;
- RosSymSection = malloc(RosSymLength);
- if (NULL == RosSymSection)
+ if (CoffSymbols)
{
- free(MergedSymbols);
- free(StringBase);
- free(FileData);
- fprintf(stderr, "Unable to allocate memory for .rossym
section\n");
- exit(1);
+ free(CoffSymbols);
}
- 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->SymbolsOffset = sizeof(SYMBOLFILE_HEADER);
- SymbolFileHeader->SymbolsLength = MergedSymbolsCount *
sizeof(ROSSYM_ENTRY);
- SymbolFileHeader->StringsOffset = SymbolFileHeader->SymbolsOffset +
SymbolFileHeader->SymbolsLength;
- SymbolFileHeader->StringsLength = StringsLength;
+ SymbolFileHeader = (PSYMBOLFILE_HEADER) RosSymSection;
+ SymbolFileHeader->SymbolsOffset = sizeof(SYMBOLFILE_HEADER);
+ SymbolFileHeader->SymbolsLength = MergedSymbolsCount *
sizeof(ROSSYM_ENTRY);
+ SymbolFileHeader->StringsOffset = SymbolFileHeader->SymbolsOffset
+ SymbolFileHeader->SymbolsLength;
+ SymbolFileHeader->StringsLength = StringsLength;
- memcpy((char *) RosSymSection + SymbolFileHeader->SymbolsOffset,
MergedSymbols,
- SymbolFileHeader->SymbolsLength);
- memcpy((char *) RosSymSection + SymbolFileHeader->StringsOffset,
StringBase,
- SymbolFileHeader->StringsLength);
+ memcpy((char *) RosSymSection + SymbolFileHeader->SymbolsOffset,
MergedSymbols,
+ SymbolFileHeader->SymbolsLength);
+ memcpy((char *) RosSymSection + SymbolFileHeader->StringsOffset,
StringBase,
+ SymbolFileHeader->StringsLength);
- free(MergedSymbols);
+ free(MergedSymbols);
+ }
free(StringBase);
-
out = fopen(path2, "wb");
if (out == NULL)
{
@@ -900,13 +935,19 @@
PESectionHeaders, RosSymLength, RosSymSection))
{
fclose(out);
- free(RosSymSection);
+ if (RosSymSection)
+ {
+ free(RosSymSection);
+ }
free(FileData);
exit(1);
}
fclose(out);
- free(RosSymSection);
+ if (RosSymSection)
+ {
+ free(RosSymSection);
+ }
free(FileData);
return 0;