https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6e33c8ffd32b6d1080f7717ca7f45e6c43efd972

commit 6e33c8ffd32b6d1080f7717ca7f45e6c43efd972
Author:     Dmitry Borisov <di.s...@protonmail.com>
AuthorDate: Thu Apr 8 20:50:51 2021 +0600
Commit:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
CommitDate: Mon May 10 00:36:38 2021 +0200

    [PEFIXUP] Fixup of resource sections in GCC builds. (#3594)
    
    Make resource sections discardable for kernel-mode drivers and DLLs.
---
 sdk/cmake/gcc.cmake |  2 +-
 sdk/tools/pefixup.c | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/sdk/cmake/gcc.cmake b/sdk/cmake/gcc.cmake
index 298a867bb45..1ab10b6f97a 100644
--- a/sdk/cmake/gcc.cmake
+++ b/sdk/cmake/gcc.cmake
@@ -307,7 +307,7 @@ function(set_module_type_toolchain MODULE TYPE)
         # Fixup section characteristics
         #  - Remove flags that LD overzealously puts (alignment flag, 
Initialized flags for code sections)
         #  - INIT section is made discardable
-        #  - .rsrc is made read-only
+        #  - .rsrc is made read-only and discardable
         #  - PAGE & .edata sections are made pageable.
         add_custom_command(TARGET ${MODULE} POST_BUILD
             COMMAND native-pefixup --${TYPE} $<TARGET_FILE:${MODULE}>)
diff --git a/sdk/tools/pefixup.c b/sdk/tools/pefixup.c
index 4d064b8574d..ac02a707769 100644
--- a/sdk/tools/pefixup.c
+++ b/sdk/tools/pefixup.c
@@ -142,9 +142,15 @@ static int driver_fixup(enum fixup_mode mode, unsigned 
char *buffer, PIMAGE_NT_H
         if (Section->Characteristics & IMAGE_SCN_CNT_CODE)
             Section->Characteristics &= ~IMAGE_SCN_CNT_INITIALIZED_DATA;
 
-        /* For some reason, .rsrc is made writable by windres */
         if (strncmp((char*)Section->Name, ".rsrc", 5) == 0)
         {
+            /* .rsrc is discardable for driver images, WDM drivers and 
Kernel-Mode DLLs */
+            if (mode == MODE_KERNELDRIVER || mode == MODE_WDMDRIVER || mode == 
MODE_KERNELDLL)
+            {
+                Section->Characteristics |= IMAGE_SCN_MEM_DISCARDABLE;
+            }
+
+            /* For some reason, .rsrc is made writable by windres */
             Section->Characteristics &= ~IMAGE_SCN_MEM_WRITE;
             continue;
         }
@@ -356,10 +362,10 @@ print_usage(void)
     printf("Usage: %s <options> <filename>\n\n", g_ApplicationName);
     printf("<options> can be one of the following options:\n"
            "  --loadconfig          Fix the LOAD_CONFIG directory entry;\n"
-           "  --kernelmodedriver    Fix code and data sections for driver 
images;\n"
-           "  --wdmdriver           Fix code and data sections for WDM 
drivers;\n"
-           "  --kerneldll           Fix code and data sections for Kernel-Mode 
DLLs;\n"
-           "  --kernel              Fix code and data sections for kernels;\n"
+           "  --kernelmodedriver    Fix code, data and resource sections for 
driver images;\n"
+           "  --wdmdriver           Fix code, data and resource sections for 
WDM drivers;\n"
+           "  --kerneldll           Fix code, data and resource sections for 
Kernel-Mode DLLs;\n"
+           "  --kernel              Fix code, data and resource sections for 
kernels;\n"
            "\n"
            "and/or a combination of the following ones:\n"
            "  --section:name[=newname][,[[!]{CDEIKOMPRSUW}][A{1248PTSX}]]\n"

Reply via email to