)]}'
{
  "commit": "fc55e181b2d84c8817e3fd9d86c6944ac709acc9",
  "tree": "17ac31e757e3770b5518675d826a85410d6fc601",
  "parents": [
    "196cbae7fa8dd83ca024005ad384381b758fb108"
  ],
  "author": {
    "name": "Pali Rohár",
    "email": "pali.rohar@gmail.com",
    "time": "Sat Dec 17 15:22:11 2022 +0100"
  },
  "committer": {
    "name": "LIU Hao",
    "email": "lh_mouse@126.com",
    "time": "Fri Dec 23 22:22:23 2022 +0800"
  },
  "message": "crt: Fix building LTO version of mingw-w64 crt libraries\n\nCurrently when linking target application with LTO builds of mingw-w64\nlibraries, it is needed to manually specify entry point of mingw-w64 crt\nstartup function via linker flag -Wl,-e,_mainCRTStartup (for console\nexecutables) or -Wl,-e,_WinMainCRTStartup (for GUI executables) or\n-Wl,-e,_DllMainCRTStartup@12 (for DLL libraries). Otherwise LTO compiler\ndrops startup function generates output binary totally broken and\nnon-working (executable crashes during during startup).\n\nThis looks like a bug in LTO compiler or GNU linker that it drops default\nentry point because GNU linker has already hardcoded symbol names of\ndefault entry points.\n\nThere is a simple way to prevent dropping some symbol by LTO compiler and\nit is by marking that symbol by __attribute__((used)).\n\nSo mark all crt startup functions by __attribute__((used)) to ensure that\nthey will be always present in final executable or DLL library. With this\nchange it is not needed to manually specify -e flag with entry point name.\n\nGNU linker tries to reference also _pei386_runtime_relocator() function\nwhen it generates pseudo-reloc data and complains if LTO compiler drops it.\nSo mark this function as used too.\n\n`__pei386_runtime_relocator\u0027 referenced in section `.rdata\u0027 of ertr000001.o: defined in discarded section `.text\u0027 of lib32_libmingw32_a-pseudo-reloc.o (symbol from plugin)\ncollect2: error: ld returned 1 exit status\n\nNote that gcc specs defined in mingw32.h already contains \"-e\" flag in its\n*link: section, so this bug does not affect building of DLL libraries with\ndefault mingw32.h gcc config file. So marking DllMainCRTStartup() as used\nis not necessary for default gcc builds but for completeness and for some\ncustom gcc builds with modified specs definitions, mark also startup\nfunction DllMainCRTStartup() as used.\n\nIt would be a nice to fix this bug in LTO compiler and GNU linker and\nallows to build mingw-w64 startup files without __attribute__((used)).\nFile crtexe.c contains startup function for both Console and GUI\nexecutables and obviously always only one is used. So LTO compiler has a\nchance can drop GUI startup function WinMainCRTStartup() for console\nexecutable (and vice-versa) but only when WinMainCRTStartup() is not marked\nas used... And same applies for _pei386_runtime_relocator() function which\nis needed only when linker generates pseudo-reloc data for executable.\n\nSigned-off-by: LIU Hao \u003clh_mouse@126.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "08cd5922a8497cba5ae220b26bea5b00061ff1f5",
      "old_mode": 33188,
      "old_path": "mingw-w64-crt/crt/crtdll.c",
      "new_id": "e264d4e9641878c9eb5f4af84e874119c5da85e5",
      "new_mode": 33188,
      "new_path": "mingw-w64-crt/crt/crtdll.c"
    },
    {
      "type": "modify",
      "old_id": "1656b0ee00062c835356af9c901891158bdb8d6a",
      "old_mode": 33188,
      "old_path": "mingw-w64-crt/crt/crtexe.c",
      "new_id": "03bda59120259833e4aeb5f01112feeb9b2f72b3",
      "new_mode": 33188,
      "new_path": "mingw-w64-crt/crt/crtexe.c"
    },
    {
      "type": "modify",
      "old_id": "5a64e0d37b18b31b5a312ccf25b40a48cffabfbe",
      "old_mode": 33188,
      "old_path": "mingw-w64-crt/crt/pseudo-reloc.c",
      "new_id": "d6eb089d461ead610244c5b91f0cbc76b2be8dbb",
      "new_mode": 33188,
      "new_path": "mingw-w64-crt/crt/pseudo-reloc.c"
    }
  ]
}
