[ros-diffs] [fireball] 32120: - Build FreeLdr the same way other modules are built, by using gcc -Wl. - This allows us to get rid of the /math directory and use -lgcc instead. - Get rid of -ffreestanding, -fno-builtin and -O2. The former are not needed anymore since we're properly building a "freestanding" image anyway, just like the kernel. The latter is removed since optimization flags come from the project settings. - Update code to fix warnings caused since we've removed -ffreestanding. GCC now warns about printf, sprintf and other C calls (including a change from %wZ to %S in winldr.c's sprintf calls). - Don't use printf anymore -- rename freeldr's implementation to TuiPrintf. Just like in the kernel, you can't use printf in freeldr (since it's not running in a standard/full CRT environment). - 124kb saved!

fireball at svn.reactos.org fireball at svn.reactos.org
Mon Feb 4 21:27:43 CET 2008


Author: fireball
Date: Mon Feb  4 23:27:43 2008
New Revision: 32120

URL: http://svn.reactos.org/svn/reactos?rev=32120&view=rev
Log:
- Build FreeLdr the same way other modules are built, by using gcc -Wl.
- This allows us to get rid of the /math directory and use -lgcc instead.
- Get rid of -ffreestanding, -fno-builtin and -O2. The former are not needed anymore since we're properly building a "freestanding" image anyway, just like the kernel. The latter is removed since optimization flags come from the project settings.
- Update code to fix warnings caused since we've removed -ffreestanding. GCC now warns about printf, sprintf and other C calls (including a change from %wZ to %S in winldr.c's sprintf calls).
- Don't use printf anymore -- rename freeldr's implementation to TuiPrintf. Just like in the kernel, you can't use printf in freeldr (since it's not running in a standard/full CRT environment).
- 124kb saved!

Removed:
    trunk/reactos/boot/freeldr/freeldr/math/
Modified:
    trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c
    trunk/reactos/boot/freeldr/freeldr/custom.c
    trunk/reactos/boot/freeldr/freeldr/disk/disk.c
    trunk/reactos/boot/freeldr/freeldr/disk/partition.c
    trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild
    trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild
    trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild
    trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild
    trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild
    trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild
    trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
    trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h
    trunk/reactos/boot/freeldr/freeldr/rtl/bget.c
    trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild
    trunk/reactos/boot/freeldr/freeldr/ui/tui.c
    trunk/reactos/boot/freeldr/freeldr/windows/winldr.c
    trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/hardware.c Mon Feb  4 23:27:43 2008
@@ -579,7 +579,7 @@
     MmHeapFree(PartialResourceList);
 
     /* Set 'Identifier' value */
-    sprintf(Identifier, "FLOPPY%u", FloppyNumber + 1);
+    sprintf(Identifier, "FLOPPY%ld", FloppyNumber + 1);
     FldrSetIdentifier(PeripheralKey, Identifier);
   }
 }
@@ -1218,7 +1218,7 @@
       MmHeapFree(PartialResourceList);
 
       /* Set 'Identifier' value */
-      sprintf(Buffer, "COM%u", i + 1);
+      sprintf(Buffer, "COM%ld", i + 1);
       FldrSetIdentifier(ControllerKey, Buffer);
       DbgPrint((DPRINT_HWDETECT,
 		"Created value: Identifier %s\n",
@@ -1323,7 +1323,7 @@
       MmHeapFree(PartialResourceList);
 
       /* Set 'Identifier' value */
-      sprintf(Buffer, "PARALLEL%u", i + 1);
+      sprintf(Buffer, "PARALLEL%ld", i + 1);
       FldrSetIdentifier(ControllerKey, Buffer);
       DbgPrint((DPRINT_HWDETECT,
 		"Created value: Identifier %s\n",

Modified: trunk/reactos/boot/freeldr/freeldr/custom.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/custom.c?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/custom.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/custom.c Mon Feb  4 23:27:43 2008
@@ -91,7 +91,7 @@
 
 	// Generate a unique section name
 	MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
-	sprintf(SectionName, "CustomBootDisk%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
+	sprintf(SectionName, "CustomBootDisk%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second);
 
 	// Add the section
 	if (!IniAddSection(SectionName, &SectionId))
@@ -140,7 +140,7 @@
 
 	// Generate a unique section name
 	MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
-	sprintf(SectionName, "CustomBootPartition%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
+	sprintf(SectionName, "CustomBootPartition%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second);
 
 	// Add the section
 	if (!IniAddSection(SectionName, &SectionId))
@@ -202,7 +202,7 @@
 
 	// Generate a unique section name
 	MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
-	sprintf(SectionName, "CustomBootSectorFile%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
+	sprintf(SectionName, "CustomBootSectorFile%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second);
 
 	// Add the section
 	if (!IniAddSection(SectionName, &SectionId))
@@ -278,7 +278,7 @@
 
 	// Generate a unique section name
 	MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
-	sprintf(SectionName, "CustomReactOS%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
+	sprintf(SectionName, "CustomReactOS%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second);
 
 	// Add the section
 	if (!IniAddSection(SectionName, &SectionId))
@@ -357,7 +357,7 @@
 
 	// Generate a unique section name
 	MachRTCGetCurrentDateTime(&Year, &Month, &Day, &Hour, &Minute, &Second);
-	sprintf(SectionName, "CustomLinux%d%d%d%d%d%d", Year, Day, Month, Hour, Minute, Second);
+	sprintf(SectionName, "CustomLinux%ld%ld%ld%ld%ld%ld", Year, Day, Month, Hour, Minute, Second);
 
 	// Add the section
 	if (!IniAddSection(SectionName, &SectionId))

Modified: trunk/reactos/boot/freeldr/freeldr/disk/disk.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/disk.c?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/disk/disk.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/disk/disk.c Mon Feb  4 23:27:43 2008
@@ -41,7 +41,7 @@
 	if (bReportError == FALSE)
 		return;
 
-	sprintf(ErrorCodeString, "%s\n\nError Code: 0x%x\nError: %s", ErrorString, ErrorCode, DiskGetErrorCodeString(ErrorCode));
+	sprintf(ErrorCodeString, "%s\n\nError Code: 0x%lx\nError: %s", ErrorString, ErrorCode, DiskGetErrorCodeString(ErrorCode));
 
 	DbgPrint((DPRINT_DISK, "%s\n", ErrorCodeString));
 

Modified: trunk/reactos/boot/freeldr/freeldr/disk/partition.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/disk/partition.c?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/disk/partition.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/disk/partition.c Mon Feb  4 23:27:43 2008
@@ -230,7 +230,7 @@
 	// Check the partition table magic value
 	if (BootRecord->MasterBootRecordMagic != 0xaa55)
 	{
-		sprintf(ErrMsg, "Invalid partition table magic 0x%x found on drive 0x%x",
+		sprintf(ErrMsg, "Invalid partition table magic 0x%x found on drive 0x%lx",
 		        BootRecord->MasterBootRecordMagic, DriveNumber);
 		DiskError(ErrMsg, 0);
 		return FALSE;

Modified: trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr.rbuild Mon Feb  4 23:27:43 2008
@@ -13,6 +13,9 @@
 			<library>cmlib</library>
 			<library>rtl</library>
 			<library>libcntpr</library>
+			<linkerflag>-nostartfiles</linkerflag>
+			<linkerflag>-nostdlib</linkerflag>
+			<linkerflag>-lgcc</linkerflag>
 		</module>
 	</if>
 	<if property="ARCH" value="powerpc">

Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr_arch.rbuild Mon Feb  4 23:27:43 2008
@@ -8,11 +8,8 @@
 				<include base="freeldr_base">cache</include>
 				<include base="ntoskrnl">include</include>
 				<define name="_NTHAL_" />
-				<compilerflag>-ffreestanding</compilerflag>
-				<compilerflag>-fno-builtin</compilerflag>
 				<compilerflag>-fno-inline</compilerflag>
 				<compilerflag>-fno-zero-initialized-in-bss</compilerflag>
-				<compilerflag>-Os</compilerflag>
 				<file>_alloca.S</file>
 				<file>archmach.c</file>
 				<file>hardware.c</file>

Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr_base.rbuild Mon Feb  4 23:27:43 2008
@@ -7,11 +7,8 @@
 	<include base="ntoskrnl">include</include>
 	<define name="_NTHAL_" />
 	<define name="_NTSYSTEM_" />
-	<compilerflag>-ffreestanding</compilerflag>
-	<compilerflag>-fno-builtin</compilerflag>
 	<compilerflag>-fno-inline</compilerflag>
 	<compilerflag>-fno-zero-initialized-in-bss</compilerflag>
-	<compilerflag>-Os</compilerflag>
 	<directory name="cache">
 		<file>blocklist.c</file>
 		<file>cache.c</file>
@@ -35,9 +32,6 @@
 		<file>ini_init.c</file>
 		<file>inifile.c</file>
 		<file>parse.c</file>
-	</directory>
-	<directory name="math">
-		<file>libgcc2.c</file>
 	</directory>
 	<directory name="mm">
 		<file>meminit.c</file>

Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr_base64k.rbuild Mon Feb  4 23:27:43 2008
@@ -4,11 +4,8 @@
 	<include base="freeldr_base64k">include</include>
 	<include base="ntoskrnl">include</include>
 	<define name="_NTHAL_" />
-	<compilerflag>-ffreestanding</compilerflag>
-	<compilerflag>-fno-builtin</compilerflag>
 	<compilerflag>-fno-inline</compilerflag>
 	<compilerflag>-fno-zero-initialized-in-bss</compilerflag>
-	<compilerflag>-Os</compilerflag>
 	<directory name="arch">
 		<if property="ARCH" value="i386">
 			<directory name="i386">

Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr_main.rbuild Mon Feb  4 23:27:43 2008
@@ -4,11 +4,8 @@
 	<include base="freeldr_main">include</include>
 	<include base="ntoskrnl">include</include>
 	<define name="_NTHAL_" />
-	<compilerflag>-ffreestanding</compilerflag>
-	<compilerflag>-fno-builtin</compilerflag>
 	<compilerflag>-fno-inline</compilerflag>
 	<compilerflag>-fno-zero-initialized-in-bss</compilerflag>
-	<compilerflag>-Os</compilerflag>
 	<file>bootmgr.c</file>
 	<file>drivemap.c</file>
 	<file>miscboot.c</file>

Modified: trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild (original)
+++ trunk/reactos/boot/freeldr/freeldr/freeldr_startup.rbuild Mon Feb  4 23:27:43 2008
@@ -3,8 +3,6 @@
 <module name="freeldr_startup" type="objectlibrary">
 	<include base="freeldr_startup">include</include>
 	<include base="ntoskrnl">include</include>
-	<compilerflag>-ffreestanding</compilerflag>
-	<compilerflag>-fno-builtin</compilerflag>
 	<compilerflag>-fno-inline</compilerflag>
 	<compilerflag>-fno-zero-initialized-in-bss</compilerflag>
 	<directory name="arch">

Modified: trunk/reactos/boot/freeldr/freeldr/include/freeldr.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/include/freeldr.h?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/freeldr.h (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/freeldr.h Mon Feb  4 23:27:43 2008
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #define NTOSAPI
+#define printf TuiPrintf
 #include <ntddk.h>
 #include <arc/arc.h>
 #include <ketypes.h>

Modified: trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/ui/tui.h Mon Feb  4 23:27:43 2008
@@ -46,7 +46,7 @@
 VOID	TuiDrawProgressBarCenter(ULONG Position, ULONG Range, PCHAR ProgressText);			// Draws the progress bar showing nPos percent filled
 VOID	TuiDrawProgressBar(ULONG Left, ULONG Top, ULONG Right, ULONG Bottom, ULONG Position, ULONG Range, PCHAR ProgressText);			// Draws the progress bar showing nPos percent filled
 BOOLEAN	TuiEditBox(PCSTR MessageText, PCHAR EditTextBuffer, ULONG Length);
-
+int	TuiPrintf(const char *format, ... );
 UCHAR	TuiTextToColor(PCSTR ColorText);						// Converts the text color into it's equivalent color value
 UCHAR	TuiTextToFillStyle(PCSTR FillStyleText);				// Converts the text fill into it's equivalent fill value
 

Modified: trunk/reactos/boot/freeldr/freeldr/rtl/bget.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/rtl/bget.c?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/rtl/bget.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/rtl/bget.c Mon Feb  4 23:27:43 2008
@@ -445,6 +445,9 @@
 
 #include <stdio.h>
 
+int TuiPrintf(const char *format, ... );
+#define printf TuiPrintf
+
 #ifdef lint
 #define NDEBUG			      /* Exits in asserts confuse lint */
 /* LINTLIBRARY */                     /* Don't complain about def, no ref */

Modified: trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild (original)
+++ trunk/reactos/boot/freeldr/freeldr/setupldr.rbuild Mon Feb  4 23:27:43 2008
@@ -11,4 +11,7 @@
 	<library>cmlib</library>
 	<library>rtl</library>
 	<library>libcntpr</library>
+	<linkerflag>-nostartfiles</linkerflag>
+	<linkerflag>-nostdlib</linkerflag>
+	<linkerflag>-lgcc</linkerflag>
 </module>

Modified: trunk/reactos/boot/freeldr/freeldr/ui/tui.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/ui/tui.c?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/ui/tui.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/ui/tui.c Mon Feb  4 23:27:43 2008
@@ -25,7 +25,7 @@
  * printf() - prints formatted text to stdout
  * originally from GRUB
  */
-int printf(const char *format, ... )
+int TuiPrintf(const char *format, ... )
 {
 	va_list ap;
 	va_start(ap,format);

Modified: trunk/reactos/boot/freeldr/freeldr/windows/winldr.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/windows/winldr.c?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/windows/winldr.c (original)
+++ trunk/reactos/boot/freeldr/freeldr/windows/winldr.c Mon Feb  4 23:27:43 2008
@@ -259,7 +259,7 @@
 	PVOID DriverBase;
 
 	// Separate the path to file name and directory path
-	sprintf(DriverPath, "%wZ", FilePath);
+	sprintf(DriverPath, "%S", FilePath->Buffer);
 	DriverNamePos = strrchr(DriverPath, '\\');
 	if (DriverNamePos != NULL)
 	{
@@ -282,7 +282,7 @@
 	}
 
 	// It's not loaded, we have to load it
-	sprintf(FullPath,"%s%wZ", BootPath, FilePath);
+	sprintf(FullPath,"%s%S", BootPath, FilePath->Buffer);
 	Status = WinLdrLoadImage(FullPath, LoaderBootDriver, &DriverBase);
 	if (!Status)
 		return FALSE;
@@ -586,3 +586,4 @@
 	}
 }
 
+

Modified: trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp?rev=32120&r1=32119&r2=32120&view=diff
==============================================================================
--- trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp (original)
+++ trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp Mon Feb  4 23:27:43 2008
@@ -3547,11 +3547,11 @@
 	fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
 
 	fprintf ( fMakefile,
-	          "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
-	          GetLinkerMacro ().c_str (),
+	          "\t${gcc} -Wl,--subsystem,native -Wl,-Ttext,0x8000 -o %s %s %s %s\n",
 	          backend->GetFullName ( junk_tmp ).c_str (),
 	          objectsMacro.c_str (),
-	          linkDepsMacro.c_str () );
+	          linkDepsMacro.c_str (),
+	          GetLinkerMacro ().c_str ());
 	fprintf ( fMakefile,
 	          "\t${objcopy} -O binary %s $@\n",
 	          backend->GetFullName ( junk_tmp ).c_str () );




More information about the Ros-diffs mailing list