All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Use linker script to remove unnecessary sections
@ 2007-12-14 12:11 Bean
  2007-12-14 16:17 ` Pavel Roskin
  2007-12-16 11:17 ` Robert Millan
  0 siblings, 2 replies; 7+ messages in thread
From: Bean @ 2007-12-14 12:11 UTC (permalink / raw)
  To: The development of GRUB 2

Hi,

This patch use customized linker script to build *.img and *.mod
files, it should remove unnecessary sections created by the compiler.


2007-12-14  Bean  <bean123ch@gmail.com>

	* conf/i386-pc.rmk (COMMON_LDFLAGS): Use ldscript to link.

	* aclocal.m4 (grub_PROG_OBJCOPY_ABSOLUTE): Test ldscript.

	* configure.ac : Remove the '--build-id=none' flag.

	* ldscript : New file.


Index: conf/i386-pc.rmk
===================================================================
RCS file: /sources/grub/grub2/conf/i386-pc.rmk,v
retrieving revision 1.94
diff -u -p -r1.94 i386-pc.rmk
--- conf/i386-pc.rmk	18 Nov 2007 06:41:45 -0000	1.94
+++ conf/i386-pc.rmk	14 Dec 2007 11:51:13 -0000
@@ -2,10 +2,10 @@

 COMMON_ASFLAGS = -nostdinc -fno-builtin -m32
 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32
-COMMON_LDFLAGS = -m32 -nostdlib
+COMMON_LDFLAGS = -m32 -nostdlib -T "${srcdir}/ldscript"

 # Images.
 pkgdata_IMAGES = boot.img diskboot.img kernel.img pxeboot.img
Index: aclocal.m4
===================================================================
RCS file: /sources/grub/grub2/aclocal.m4,v
retrieving revision 1.7
diff -u -p -r1.7 aclocal.m4
--- aclocal.m4	25 Nov 2007 02:01:30 -0000	1.7
+++ aclocal.m4	14 Dec 2007 11:51:14 -0000
@@ -57,7 +57,7 @@ else
 fi
 grub_cv_prog_objcopy_absolute=yes
 for link_addr in 2000 8000 7C00; do
-  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N
-Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
+  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-T
"-Wl,${srcdir}/ldscript" -Wl,-Ttext -Wl,$link_addr conftest.o -o
conftest.exec]); then :
   else
     AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
   fi
Index: configure.ac
===================================================================
RCS file: /sources/grub/grub2/configure.ac,v
retrieving revision 1.40
diff -u -p -r1.40 configure.ac
--- configure.ac	25 Nov 2007 02:01:30 -0000	1.40
+++ configure.ac	14 Dec 2007 11:51:14 -0000
@@ -229,16 +229,6 @@ if test "x$target_m32" = x1; then
   TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
 fi

-AC_MSG_CHECKING([whether the linker accepts `--build-id=none'])
-save_LDFLAGS="$LDFLAGS"
-LDFLAGS="$LDFLAGS -Wl,--build-id=none"
-AC_TRY_LINK(, , build_id_flag=yes, build_id_flag=no)
-AC_MSG_RESULT([$build_id_flag])
-LDFLAGS="$save_LDFLAGS"
-if test "x$build_id_flag" = xyes; then
-  TARGET_LDFLAGS="$TARGET_LDFLAGS -Wl,--build-id=none"
-fi
-
 #
 # Compiler features.
 #
Index: ldscript
===================================================================
RCS file: /sources/grub/grub2/ldscript,v
diff -Nu ldscript
--- /dev/null	2007-12-15 02:52:31.284046226 +0800
+++ ldscript	2007-12-14 19:37:39.546875000 +0800
@@ -0,0 +1,12 @@
+SECTIONS
+{
+  .text : { *(.text) } =0x90909090
+  .rodata : { *(.rodata .rodata.*) }
+  .data : { *(.data) }
+  PROVIDE(__bss_start = .);
+  .bss : { *(.bss) *(COMMON) }
+  PROVIDE(end = .);
+  .modname : { *(.modname) }
+  .moddep : { *(.moddep) }
+  /DISCARD/ : { *(*) }
+}

-- 
Bean



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use linker script to remove unnecessary sections
  2007-12-14 12:11 [PATCH] Use linker script to remove unnecessary sections Bean
@ 2007-12-14 16:17 ` Pavel Roskin
  2007-12-14 18:01   ` Christian Franke
  2007-12-16 11:17 ` Robert Millan
  1 sibling, 1 reply; 7+ messages in thread
From: Pavel Roskin @ 2007-12-14 16:17 UTC (permalink / raw)
  To: The development of GRUB 2, Bean

Quoting Bean <bean123ch@gmail.com>:

> Hi,
>
> This patch use customized linker script to build *.img and *.mod
> files, it should remove unnecessary sections created by the compiler.

Thanks!  Looks good to me.  Actually, if we stop using objcopy, we  
don't need to test it at all.  Or we can reuse the test to test ld in  
place of objcopy.

I tend to prefer the removal of grub_PROG_OBJCOPY_ABSOLUTE, as it's  
designed to find a specific bug in some old version of objcopy, and if  
we discover any issues with ld (I hope not), we'll have to use  
different tests to detect them.

We may want to use architecture specific ld scripts, but that can be  
corrected in further patches.

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use linker script to remove unnecessary sections
  2007-12-14 16:17 ` Pavel Roskin
@ 2007-12-14 18:01   ` Christian Franke
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Franke @ 2007-12-14 18:01 UTC (permalink / raw)
  To: The development of GRUB 2

Bean wrote:
> ...
> diff -u -p -r1.7 aclocal.m4
> --- aclocal.m4	25 Nov 2007 02:01:30 -0000	1.7
> +++ aclocal.m4	14 Dec 2007 11:51:14 -0000
> @@ -57,7 +57,7 @@ else
>  fi
>  grub_cv_prog_objcopy_absolute=yes
>  for link_addr in 2000 8000 7C00; do
> -  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N
> -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
> +  if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-T
> "-Wl,${srcdir}/ldscript" -Wl,-Ttext -Wl,$link_addr conftest.o -o
> conftest.exec]); then :
>   

Selecting the builtin "-N" script first has no effect if a custom script 
is specified later. Therefore, "-Wl,-N" is IMO no longer necessary.


Pavel Roskin wrote:
> ...
> We may want to use architecture specific ld scripts, but that can be 
> corrected in further patches.

See "[PATCH] Build on Cygwin" for a working example on how to select a 
platform specific linker script in configure.ac. This can be easily 
extended, e.g. test more specific scripts first:

  for f in \
    ${target_cpu}-${platform}-${target_os} \
    ${target_cpu}-${platform} \
    ${target_cpu}; do
    if test -f "${srcdir}/conf/$f-img-ld.sc"; then ...


Christian




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use linker script to remove unnecessary sections
  2007-12-14 12:11 [PATCH] Use linker script to remove unnecessary sections Bean
  2007-12-14 16:17 ` Pavel Roskin
@ 2007-12-16 11:17 ` Robert Millan
  2007-12-16 16:29   ` Pavel Roskin
  1 sibling, 1 reply; 7+ messages in thread
From: Robert Millan @ 2007-12-16 11:17 UTC (permalink / raw)
  To: The development of GRUB 2

On Fri, Dec 14, 2007 at 08:11:36PM +0800, Bean wrote:
> Hi,
> 
> This patch use customized linker script to build *.img and *.mod
> files, it should remove unnecessary sections created by the compiler.
> 
> 
> 2007-12-14  Bean  <bean123ch@gmail.com>
> 
> 	* conf/i386-pc.rmk (COMMON_LDFLAGS): Use ldscript to link.
> 
> 	* aclocal.m4 (grub_PROG_OBJCOPY_ABSOLUTE): Test ldscript.
> 
> 	* configure.ac : Remove the '--build-id=none' flag.

This probably breaks other targets than i386-pc.  linuxbios and ieee1275
both use ELF.

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use linker script to remove unnecessary sections
  2007-12-16 11:17 ` Robert Millan
@ 2007-12-16 16:29   ` Pavel Roskin
  2007-12-16 16:39     ` Robert Millan
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Roskin @ 2007-12-16 16:29 UTC (permalink / raw)
  To: The development of GRUB 2, Robert Millan

Quoting Robert Millan <rmh@aybabtu.com>:

> On Fri, Dec 14, 2007 at 08:11:36PM +0800, Bean wrote:
>> Hi,
>>
>> This patch use customized linker script to build *.img and *.mod
>> files, it should remove unnecessary sections created by the compiler.
>>
>>
>> 2007-12-14  Bean  <bean123ch@gmail.com>
>>
>> 	* conf/i386-pc.rmk (COMMON_LDFLAGS): Use ldscript to link.
>>
>> 	* aclocal.m4 (grub_PROG_OBJCOPY_ABSOLUTE): Test ldscript.
>>
>> 	* configure.ac : Remove the '--build-id=none' flag.
>
> This probably breaks other targets than i386-pc.  linuxbios and ieee1275
> both use ELF.

But they don't use objcopy, they use strip.  The goal is to switch  
i386-pc from the buggy and simple objcopy to more powerful and  
flexible ld.  The same could be done to replace strip for other  
platforms while keeping ELF format for the output.

I agree that we should avoid naming highly target-specific linker  
scripts in a generic way.  "i386-pc.ld" might be a better name.  The  
linker script for modules perhaps could be generic, but this is for  
*.img files.

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use linker script to remove unnecessary sections
  2007-12-16 16:29   ` Pavel Roskin
@ 2007-12-16 16:39     ` Robert Millan
  2007-12-16 21:21       ` Christian Franke
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Millan @ 2007-12-16 16:39 UTC (permalink / raw)
  To: The development of GRUB 2

On Sun, Dec 16, 2007 at 11:29:31AM -0500, Pavel Roskin wrote:
> 
> I agree that we should avoid naming highly target-specific linker  
> scripts in a generic way.  "i386-pc.ld" might be a better name.

or i386/pc/ld (more consistent with the rest of grub)

-- 
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call, if you are unable to speak?
(as seen on /.)



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Use linker script to remove unnecessary sections
  2007-12-16 16:39     ` Robert Millan
@ 2007-12-16 21:21       ` Christian Franke
  0 siblings, 0 replies; 7+ messages in thread
From: Christian Franke @ 2007-12-16 21:21 UTC (permalink / raw)
  To: The development of GRUB 2

Robert Millan wrote:
> On Sun, Dec 16, 2007 at 11:29:31AM -0500, Pavel Roskin wrote:
>   
>> I agree that we should avoid naming highly target-specific linker  
>> scripts in a generic way.  "i386-pc.ld" might be a better name.
>>     
>
> or i386/pc/ld (more consistent with the rest of grub)
>
>   

or "i386/pc/img.ld" (ld script to produce .img files).

Should this dir structure reside in "conf" ? This scheme is not yet used 
for the *mk files in this directory.

Christian




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-12-16 21:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-14 12:11 [PATCH] Use linker script to remove unnecessary sections Bean
2007-12-14 16:17 ` Pavel Roskin
2007-12-14 18:01   ` Christian Franke
2007-12-16 11:17 ` Robert Millan
2007-12-16 16:29   ` Pavel Roskin
2007-12-16 16:39     ` Robert Millan
2007-12-16 21:21       ` Christian Franke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.