[Git][ghc/ghc][wip/andreask/linker_fix] debug wibbles
Andreas Klebinger pushed to branch wip/andreask/linker_fix at Glasgow Haskell Compiler / GHC Commits: 2c39a9a3 by Andreas Klebinger at 2026-01-29T13:32:00+01:00 debug wibbles - - - - - 4 changed files: - rts/Linker.c - rts/linker/LoadArchive.c - rts/linker/MachO.c - rts/linker/PEi386.c Changes: ===================================== rts/Linker.c ===================================== @@ -1415,7 +1415,7 @@ preloadObjectFile (pathchar *path) // We calculate the correct alignment from the header before // reading the file, and then we misalign image on purpose so // that the actual sections end up aligned again. - machoGetMisalignment(f, &misalignment); + int valid_macho = machoGetMisalignment(f, &misalignment); //machoGetMisalignment might fail to parse the header, but in that //case so will verifyAndInitOc so we leave cleanup to after verifyAndInitOc. image = stgMallocBytes(fileSize + misalignment, "loadObj(image)"); @@ -1504,7 +1504,7 @@ HsInt loadObj (pathchar *path) return r; } -// Call the relevant VeriffyImage_* and ocInit_* functions. +// Call the relevant VerifyImage_* and ocInit_* functions. // Return 1 on success. HsInt verifyAndInitOc (ObjectCode* oc) { ===================================== rts/linker/LoadArchive.c ===================================== @@ -26,6 +26,7 @@ #include <ctype.h> #include <sys/types.h> #include <fs_rts.h> +#include <stdio.h> #define FAIL(...) do {\ errorBelch("loadArchive: "__VA_ARGS__); \ @@ -33,6 +34,7 @@ } while (0) #define DEBUG_LOG(...) IF_DEBUG(linker, debugBelch("loadArchive: " __VA_ARGS__)) +#define DEBUG_LOG_ALWAYS(...) (fprintf(stderr, "loadArchive: " __VA_ARGS__)) #if defined(darwin_HOST_OS) || defined(ios_HOST_OS) @@ -344,7 +346,7 @@ HsInt loadArchive_ (pathchar *path) Ignore requests to load multiple times */ if (isAlreadyLoaded(path)) { IF_DEBUG(linker, - debugBelch("ignoring repeated load of %" PATH_FMT "\n", path)); + DEBUG_LOG("ignoring repeated load of %" PATH_FMT "\n", path)); return 1; /* success */ } @@ -365,6 +367,7 @@ HsInt loadArchive_ (pathchar *path) bool isThin = archive_fmt == ThinArchive; if(isThin) { DEBUG_LOG("Found thin archive.\n"); + DEBUG_LOG_ALWAYS("Found thin archive.\n"); } DEBUG_LOG("loading archive contents\n"); @@ -630,6 +633,7 @@ HsInt loadArchive_ (pathchar *path) if (0 == loadOc(oc)) { + errorBelch("Failed to load OC %" PATH_FMT " , aborting.\n", path); stgFree(fileName); fclose(f); return 0; ===================================== rts/linker/MachO.c ===================================== @@ -175,7 +175,7 @@ resolveImports( int ocAllocateExtras_MachO(ObjectCode* oc) { - IF_DEBUG(linker, debugBelch("ocAllocateExtras_MachO: start\n")); + IF_DEBUG(linker, DEBUG_LOG_ALWAYS("ocAllocateExtras_MachO: start\n")); if (NULL != oc->info->symCmd) { IF_DEBUG(linker, @@ -200,6 +200,10 @@ int ocVerifyImage_MachO(ObjectCode * oc) { char *image = (char*) oc->image; + if (oc->fileSize < sizeof(MachOHeader)) { + errorBelch("Tried loading machO smaller than header size.\n"); + return 0; + } MachOHeader *header = (MachOHeader*) image; IF_DEBUG(linker, debugBelch("ocVerifyImage_MachO: start\n")); ===================================== rts/linker/PEi386.c ===================================== @@ -475,7 +475,7 @@ static void addDLLHandle( static bool verifyCOFFHeader( uint16_t machine, - IMAGE_FILE_HEADER *hdr + IMAGE_FILE_HEADER *hdr, pathchar *fileName); static bool checkIfDllLoaded( View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2c39a9a3c98b958e0d4f2da917e10677... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2c39a9a3c98b958e0d4f2da917e10677... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Andreas Klebinger (@AndreasK)