Skip to content

Commit a68573d

Browse files
committed
[BOOTLIB]: Fuck you binutils.
svn path=/trunk/; revision=70636
1 parent 1250609 commit a68573d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

reactos/boot/environ/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ add_executable(rosload ${ROSLOAD_BASE_SOURCE})
113113
set_target_properties(rosload PROPERTIES SUFFIX ".efi")
114114

115115
if(MSVC)
116-
add_target_link_flags(rosload "/ignore:4078 /ignore:4254 /DRIVER /FIXED")
116+
add_target_link_flags(rosload "/ignore:4078 /ignore:4254 /DRIVER")
117117
else()
118-
add_target_link_flags(rosload "-Wl,--strip-all,--exclude-all-symbols")
118+
add_target_link_flags(rosload "-Wl,--strip-all,--exclude-all-symbols,--dynamicbase,--pic-executable")
119119
endif()
120120

121121
set_image_base(rosload 0x10000)

reactos/boot/environ/lib/misc/image.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,10 @@ ImgpLoadPEImage (
677677
BOOLEAN First, ImageHashValid;
678678
UCHAR LocalBuffer[1024];
679679
UCHAR TrustedBootInformation[52];
680+
ULONG WorkaroundForBinutils;
680681

681682
/* Initialize locals */
683+
WorkaroundForBinutils = 0;
682684
LocalFile = NULL;
683685
ImageBuffer = NULL;
684686
FileSize = 0;
@@ -881,6 +883,7 @@ ImgpLoadPEImage (
881883

882884
/* Record our current position (right after the headers) */
883885
EndOfHeaders = (ULONG_PTR)VirtualAddress + HeaderSize;
886+
EfiPrintf(L"here\r\n");
884887

885888
/* Get the first section and iterate through each one */
886889
Section = IMAGE_FIRST_SECTION(NtHeaders);
@@ -893,6 +896,7 @@ ImgpLoadPEImage (
893896
if ((VirtualSize < Section->VirtualAddress) ||
894897
((PVOID)SectionStart < VirtualAddress))
895898
{
899+
EfiPrintf(L"fail 1\r\n");
896900
Status = STATUS_INVALID_IMAGE_FORMAT;
897901
goto Quickie;
898902
}
@@ -940,6 +944,7 @@ ImgpLoadPEImage (
940944
&SectionEnd);
941945
if (!NT_SUCCESS(Status))
942946
{
947+
EfiPrintf(L"fail 21\r\n");
943948
Status = STATUS_INVALID_IMAGE_FORMAT;
944949
goto Quickie;
945950
}
@@ -957,6 +962,7 @@ ImgpLoadPEImage (
957962
&SectionEnd);
958963
if (!NT_SUCCESS(Status))
959964
{
965+
EfiPrintf(L"fail 31\r\n");
960966
Status = STATUS_INVALID_IMAGE_FORMAT;
961967
goto Quickie;
962968
}
@@ -974,6 +980,20 @@ ImgpLoadPEImage (
974980
/* Are we in the first iteration? */
975981
if (!First)
976982
{
983+
/* FUCK YOU BINUTILS */
984+
if ((*(PULONG)&Section->Name == 'ler.') && (RawSize < AlignSize))
985+
{
986+
/* Piece of shit won't build relocations when you tell it to,
987+
* either by using --emit-relocs or --dynamicbase. People online
988+
* have found out that by using -pie-executable you can get this
989+
* to happen, but then it turns out that the .reloc section is
990+
* incorrectly sized, and results in a corrupt PE. However, they
991+
* still compute the checksum using the correct value. What idiots.
992+
*/
993+
WorkaroundForBinutils = AlignSize - RawSize;
994+
AlignSize -= WorkaroundForBinutils;
995+
}
996+
977997
/* Yes, read the section data */
978998
Status = ImgpReadAtFileOffset(LocalFile,
979999
AlignSize,
@@ -994,6 +1014,7 @@ ImgpLoadPEImage (
9941014
AlignSize,
9951015
BL_UTL_CHECKSUM_COMPLEMENT |
9961016
BL_UTL_CHECKSUM_USHORT_BUFFER);
1017+
AlignSize += WorkaroundForBinutils;
9971018
}
9981019
}
9991020

@@ -1075,7 +1096,7 @@ ImgpLoadPEImage (
10751096
}
10761097

10771098
/* Finally, calculate the final checksum and compare it */
1078-
FinalSum = FileSize + PartialSum;
1099+
FinalSum = FileSize + PartialSum + WorkaroundForBinutils;
10791100
if ((FinalSum != CheckSum) && (PartialSum == 0xFFFF))
10801101
{
10811102
/* It hit overflow, so set it to the file size */
@@ -1148,9 +1169,6 @@ ImgpLoadPEImage (
11481169
*ImageSize = VirtualSize;
11491170
}
11501171

1151-
EfiPrintf(L"MORE PE TODO: %lx\r\n", NtHeaders->OptionalHeader.AddressOfEntryPoint);
1152-
EfiStall(100000000);
1153-
11541172
Quickie:
11551173
/* Check if we computed the image hash OK */
11561174
if (ImageHashValid)

0 commit comments

Comments
 (0)