https://git.reactos.org/?p=reactos.git;a=commitdiff;h=77d69c68b89bcd28b98652fad639ea1b77ac2461

commit 77d69c68b89bcd28b98652fad639ea1b77ac2461
Author:     Hervé Poussineau <[email protected]>
AuthorDate: Mon Feb 22 10:06:20 2021 +0100
Commit:     Hervé Poussineau <[email protected]>
CommitDate: Mon Feb 22 14:21:43 2021 +0100

    [OBJ2BIN] Add support for IMAGE_REL_I386_REL16
    
    Also return error in case of unknown relocation type.
---
 sdk/include/host/pecoff.h   |  1 +
 sdk/tools/obj2bin/obj2bin.c | 23 ++++++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/sdk/include/host/pecoff.h b/sdk/include/host/pecoff.h
index 14e267c9662..28daca13da4 100644
--- a/sdk/include/host/pecoff.h
+++ b/sdk/include/host/pecoff.h
@@ -42,6 +42,7 @@
 #define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
 
 #define IMAGE_REL_I386_ABSOLUTE 0x0001
+#define IMAGE_REL_I386_REL16    0x0002
 #define IMAGE_REL_I386_DIR32    0x0006
 
 #pragma pack(push,2)
diff --git a/sdk/tools/obj2bin/obj2bin.c b/sdk/tools/obj2bin/obj2bin.c
index 07b07670338..3f49775b1d4 100644
--- a/sdk/tools/obj2bin/obj2bin.c
+++ b/sdk/tools/obj2bin/obj2bin.c
@@ -13,7 +13,7 @@ Usage(void)
 }
 
 static
-void
+int
 RelocateSection(
     char *pData,
     IMAGE_SECTION_HEADER *pSectionHeader,
@@ -46,6 +46,11 @@ RelocateSection(
                 *p16 += (WORD)(pSymbols[pReloc->SymbolTableIndex].Value + 
iOffset);
                 break;
 
+            case IMAGE_REL_I386_REL16:
+                p16 = (void*)(pSection + nOffset);
+                *p16 += (WORD)(pSymbols[pReloc->SymbolTableIndex].Value + 
iOffset);
+                break;
+
             case IMAGE_REL_I386_DIR32:
                 p32 = (void*)(pSection + nOffset);
                 *p32 += (DWORD)(pSymbols[pReloc->SymbolTableIndex].Value + 
iOffset);
@@ -54,10 +59,13 @@ RelocateSection(
             default:
                 printf("Unknown relocation type %u, address 0x%x\n",
                        pReloc->Type, (unsigned)pReloc->VirtualAddress);
+                return 0;
         }
 
         pReloc++;
     }
+
+    return 1;
 }
 
 int main(int argc, char *argv[])
@@ -136,10 +144,15 @@ int main(int argc, char *argv[])
         if ((strcmp((char*)pSectionHeader->Name, ".text") == 0) &&
             (pSectionHeader->SizeOfRawData != 0))
         {
-            RelocateSection(pData,
-                            pSectionHeader,
-                            pSymbols,
-                            nBaseAddress);
+            if (!RelocateSection(pData,
+                                 pSectionHeader,
+                                 pSymbols,
+                                 nBaseAddress))
+            {
+                free(pData);
+                fclose(pDestFile);
+                return -7;
+            }
 
             /* Write the section to the destination file */
             if (!fwrite(pData + pSectionHeader->PointerToRawData,

Reply via email to