linker script: unify usage of discard definition
authorTejun Heo <tj@kernel.org>
Thu, 9 Jul 2009 02:27:40 +0000 (11:27 +0900)
committerTejun Heo <tj@kernel.org>
Thu, 9 Jul 2009 02:27:40 +0000 (11:27 +0900)
Discarded sections in different archs share some commonality but have
considerable differences.  This led to linker script for each arch
implementing its own /DISCARD/ definition, which makes maintaining
tedious and adding new entries error-prone.

This patch makes all linker scripts to move discard definitions to the
end of the linker script and use the common DISCARDS macro.  As ld
uses the first matching section definition, archs can include default
discarded sections by including them earlier in the linker script.

ia64 is notable because it first throws away some ia64 specific
subsections and then include the rest of the sections into the final
image, so those sections must be discarded before the inclusion.

defconfig compile tested for x86, x86-64, powerpc, powerpc64, ia64,
alpha, sparc, sparc64 and s390.  Michal Simek tested microblaze.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Acked-by: Mike Frysinger <vapier@gentoo.org>
Tested-by: Michal Simek <monstr@monstr.eu>
Cc: linux-arch@vger.kernel.org
Cc: Michal Simek <monstr@monstr.eu>
Cc: microblaze-uclinux@itee.uq.edu.au
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Tony Luck <tony.luck@intel.com>
25 files changed:
arch/alpha/kernel/vmlinux.lds.S
arch/avr32/kernel/vmlinux.lds.S
arch/blackfin/kernel/vmlinux.lds.S
arch/cris/kernel/vmlinux.lds.S
arch/frv/kernel/vmlinux.lds.S
arch/h8300/kernel/vmlinux.lds.S
arch/ia64/kernel/vmlinux.lds.S
arch/m32r/kernel/vmlinux.lds.S
arch/m68k/kernel/vmlinux-std.lds
arch/m68k/kernel/vmlinux-sun3.lds
arch/m68knommu/kernel/vmlinux.lds.S
arch/microblaze/kernel/vmlinux.lds.S
arch/mips/kernel/vmlinux.lds.S
arch/mn10300/kernel/vmlinux.lds.S
arch/parisc/kernel/vmlinux.lds.S
arch/powerpc/kernel/vmlinux.lds.S
arch/s390/kernel/vmlinux.lds.S
arch/sh/kernel/vmlinux.lds.S
arch/sparc/kernel/vmlinux.lds.S
arch/um/include/asm/common.lds.S
arch/um/kernel/dyn.lds.S
arch/um/kernel/uml.lds.S
arch/x86/kernel/vmlinux.lds.S
arch/xtensa/kernel/vmlinux.lds.S
include/asm-generic/vmlinux.lds.h

index 75fe1d6877e9ec07f5a785c8c0a64aaa9b83b6ad..6dc03c35caa0246bb87dc69c0add025e1f46ab94 100644 (file)
@@ -134,14 +134,6 @@ SECTIONS
        __bss_stop = .;
        _end = .;
 
-       /* Sections to be discarded */
-       /DISCARD/ : {
-               EXIT_TEXT
-               EXIT_DATA
-               *(.exitcall.exit)
-               *(.discard)
-       }
-
        .mdebug 0 : {
                *(.mdebug)
        }
@@ -151,4 +143,6 @@ SECTIONS
 
        STABS_DEBUG
        DWARF_DEBUG
+
+       DISCARDS
 }
index b8324608ec0c9b8ee5db861576d159e3b8bd6bce..c4b56654349adbb8fb52fd2f4a12602a3942391c 100644 (file)
@@ -124,15 +124,11 @@ SECTIONS
                _end = .;
        }
 
+       DWARF_DEBUG
+
        /* When something in the kernel is NOT compiled as a module, the module
         * cleanup code and data are put into these segments. Both can then be
         * thrown away, as cleanup code is never called unless it's a module.
         */
-       /DISCARD/               : {
-               EXIT_DATA
-               *(.exitcall.exit)
-               *(.discard)
-       }
-
-       DWARF_DEBUG
+       DISCARDS
 }
index 6e8eabd8f0a6dd9e5afe68a7b57d9095a49b0797..d7ffe299b979340de6264310434913ead137c775 100644 (file)
@@ -277,9 +277,5 @@ SECTIONS
 
        DWARF_DEBUG
 
-       /DISCARD/ :
-       {
-               *(.exitcall.exit)
-               *(.discard)
-       }
+       DISCARDS
 }
index a3175ebb38ccfa62a64d93f4fcf7cb06d2e0a104..6c81836b9229cb473aece3a99468020085647cf5 100644 (file)
@@ -140,13 +140,7 @@ SECTIONS
        _end = .;
        __end = .;
 
-       /* Sections to be discarded */
-       /DISCARD/ : {
-               EXIT_TEXT
-               EXIT_DATA
-               *(.exitcall.exit)
-               *(.discard)
-        }
-
        dram_end = dram_start + (CONFIG_ETRAX_DRAM_SIZE - __CONFIG_ETRAX_VMEM_SIZE)*1024*1024;
+
+       DISCARDS
 }
index 64b5a5e4d35e77040c398871a6f40c9afc07c7df..7dbf41f68b523a14f7c39b683689c51f53c99f4f 100644 (file)
@@ -178,7 +178,7 @@ SECTIONS
 
   .comment 0 : { *(.comment) }
 
-  /DISCARD/ : { *(.discard) }
+  DISCARDS
 }
 
 __kernel_image_size_no_bss = __bss_start - __kernel_image_start;
index 03d6c0df33db44462aee6e8c290acc8e0dffe37b..662b02ecb86eacfd068e65b3c73a14e11760813d 100644 (file)
@@ -152,10 +152,6 @@ SECTIONS
        __end = . ;
        __ramstart = .;
        }
-       /DISCARD/ : {
-               *(.exitcall.exit)
-               *(.discard)
-       }
         .romfs :       
        {
                *(.romfs*)
@@ -166,4 +162,6 @@ SECTIONS
        COMMAND_START = . - 0x200 ;
        __ramend = . ;
        }
+
+       DISCARDS
 }
index 13d958975874bba06d9060eecdd4fa8421e9eb82..eb4214d1c5afe342729901da138870302676f6d9 100644 (file)
@@ -24,15 +24,14 @@ PHDRS {
 }
 SECTIONS
 {
-  /* Sections to be discarded */
+  /* unwind exit sections must be discarded before the rest of the
+     sections get included. */
   /DISCARD/ : {
-       EXIT_TEXT
-       EXIT_DATA
-       *(.exitcall.exit)
-       *(.discard)
        *(.IA_64.unwind.exit.text)
        *(.IA_64.unwind_info.exit.text)
-       }
+       *(.comment)
+       *(.note)
+  }
 
   v = PAGE_OFFSET;     /* this symbol is here to make debugging easier... */
   phys_start = _start - LOAD_OFFSET;
@@ -317,7 +316,7 @@ SECTIONS
   .debug_funcnames 0 : { *(.debug_funcnames) }
   .debug_typenames 0 : { *(.debug_typenames) }
   .debug_varnames  0 : { *(.debug_varnames) }
-  /* These must appear regardless of  .  */
-  /DISCARD/ : { *(.comment) }
-  /DISCARD/ : { *(.note) }
+
+  /* Default discards */
+  DISCARDS
 }
index 480a49944cfd426c5d05bda87a69e676b4e41071..de5e21cca6a5a323d6a5eb3232694863cef05a36 100644 (file)
@@ -120,14 +120,6 @@ SECTIONS
 
   _end = . ;
 
-  /* Sections to be discarded */
-  /DISCARD/ : {
-       EXIT_TEXT
-       EXIT_DATA
-       *(.exitcall.exit)
-       *(.discard)
-       }
-
   /* Stabs debugging sections.  */
   .stab 0 : { *(.stab) }
   .stabstr 0 : { *(.stabstr) }
@@ -136,4 +128,7 @@ SECTIONS
   .stab.index 0 : { *(.stab.index) }
   .stab.indexstr 0 : { *(.stab.indexstr) }
   .comment 0 : { *(.comment) }
+
+  /* Sections to be discarded */
+  DISCARDS
 }
index 905a797ada935a3a1a2517cb38bd61537efe01ee..47eac19e8f61d68c7ecbd26de4704e133e213852 100644 (file)
@@ -82,14 +82,6 @@ SECTIONS
 
   _end = . ;
 
-  /* Sections to be discarded */
-  /DISCARD/ : {
-       EXIT_TEXT
-       EXIT_DATA
-       *(.exitcall.exit)
-       *(.discard)
-       }
-
   /* Stabs debugging sections.  */
   .stab 0 : { *(.stab) }
   .stabstr 0 : { *(.stabstr) }
@@ -98,4 +90,7 @@ SECTIONS
   .stab.index 0 : { *(.stab.index) }
   .stab.indexstr 0 : { *(.stab.indexstr) }
   .comment 0 : { *(.comment) }
+
+  /* Sections to be discarded */
+  DISCARDS
 }
index 47d04be322aac4e86dc5350193f4ca1fd8beb936..03efaf04d7d7dad17f37a1f95dd454a6b64ea8b3 100644 (file)
@@ -77,14 +77,6 @@ __init_begin = .;
 
   _end = . ;
 
-  /* Sections to be discarded */
-  /DISCARD/ : {
-       EXIT_TEXT
-       EXIT_DATA
-       *(.exitcall.exit)
-       *(.discard)
-       }
-
   .crap : {
        /* Stabs debugging sections.  */
        *(.stab)
@@ -97,4 +89,6 @@ __init_begin = .;
        *(.note)
   }
 
+  /* Sections to be discarded */
+  DISCARDS
 }
index 68111a61a77f26f175a3cc15931f88d482b04dac..2736a5e309c0d1b386f2be27b3b3477d58e4a5c1 100644 (file)
@@ -184,13 +184,6 @@ SECTIONS {
                __init_end = .;
        } > INIT
 
-       /DISCARD/ : {
-               EXIT_TEXT
-               EXIT_DATA
-               *(.exitcall.exit)
-               *(.discard)
-       }
-
        .bss : {
                . = ALIGN(4);
                _sbss = . ;
@@ -201,5 +194,6 @@ SECTIONS {
                _end = . ;
        } > BSS
 
+       DISCARDS
 }
 
index 81bebdcb18fe71d8a6c72e8415e58fc9e41964ad..ec5fa91a48d83bf515912011bd0f48e6419113e6 100644 (file)
@@ -163,5 +163,5 @@ SECTIONS {
        . = ALIGN(4096);
        _end = .;
 
-       /DISCARD/ : { *(.discard) }
+       DISCARDS
 }
index 45901609b741df293b027fe0dffba7822c54b122..1474c18fb777d13c1d07f164f50ccef1304f156b 100644 (file)
@@ -176,18 +176,6 @@ SECTIONS
 
        _end = . ;
 
-       /* Sections to be discarded */
-       /DISCARD/ : {
-               *(.exitcall.exit)
-               *(.discard)
-
-               /* ABI crap starts here */
-               *(.MIPS.options)
-               *(.options)
-               *(.pdr)
-               *(.reginfo)
-       }
-
        /* These mark the ABI of the kernel for debuggers.  */
        .mdebug.abi32 : {
                KEEP(*(.mdebug.abi32))
@@ -213,4 +201,14 @@ SECTIONS
                *(.gptab.bss)
                *(.gptab.sbss)
        }
+
+       /* Sections to be discarded */
+       DISCARDS
+       /DISCARD/ : {
+               /* ABI crap starts here */
+               *(.MIPS.options)
+               *(.options)
+               *(.pdr)
+               *(.reginfo)
+       }
 }
index 5609d4962a55d58bac652b6a5757b87e2c2915c6..8fcd0f1e21deafef6da4a3f32c39b29b4887ce8a 100644 (file)
@@ -115,13 +115,10 @@ SECTIONS
   . = ALIGN(PAGE_SIZE);
   pg0 = .;
 
-  /* Sections to be discarded */
-  /DISCARD/ : {
-       EXIT_CALL
-       *(.discard)
-       }
-
   STABS_DEBUG
 
   DWARF_DEBUG
+
+  /* Sections to be discarded */
+  DISCARDS
 }
index ccf58341845a1484b529c08d251d475613fdfcdb..aea1784edbd122d0fd5533edd29fb3d9cd659c64 100644 (file)
@@ -237,10 +237,12 @@ SECTIONS
        /* freed after init ends here */
        _end = . ;
 
+       STABS_DEBUG
+       .note 0 : { *(.note) }
+
        /* Sections to be discarded */
+       DISCARDS
        /DISCARD/ : {
-               *(.exitcall.exit)
-               *(.discard)
 #ifdef CONFIG_64BIT
                /* temporary hack until binutils is fixed to not emit these
                 * for static binaries
@@ -253,7 +255,4 @@ SECTIONS
                *(.gnu.hash)
 #endif
        }
-
-       STABS_DEBUG
-       .note 0 : { *(.note) }  
 }
index 7fca9355fd3d6a1fffce12d8cc7d09d30a250f36..244e3658983c226352721e23d1c13d858b2e05b1 100644 (file)
@@ -37,13 +37,6 @@ jiffies = jiffies_64 + 4;
 #endif
 SECTIONS
 {
-       /* Sections to be discarded. */
-       /DISCARD/ : {
-       *(.exitcall.exit)
-       *(.discard)
-       EXIT_DATA
-       }
-
        . = KERNELBASE;
 
 /*
@@ -299,4 +292,7 @@ SECTIONS
        . = ALIGN(PAGE_SIZE);
        _end = . ;
        PROVIDE32 (end = .);
+
+       /* Sections to be discarded. */
+       DISCARDS
 }
index 98867dfea4696ac9cffe386934b500a9aa14f6ad..82415c75b996447a202cbda9fe032222bc45eb6a 100644 (file)
@@ -157,14 +157,10 @@ SECTIONS
 
        _end = . ;
 
-       /* Sections to be discarded */
-       /DISCARD/ : {
-               EXIT_DATA
-               *(.exitcall.exit)
-               *(.discard)
-       }
-
        /* Debugging sections.  */
        STABS_DEBUG
        DWARF_DEBUG
+
+       /* Sections to be discarded */
+       DISCARDS
 }
index 766976d27b21960c0a205ee454fc129a8a84633e..0ce254bca92fc5ce2541ec4e0080df97c17c97ed 100644 (file)
@@ -163,17 +163,14 @@ SECTIONS
                _end = . ;
        }
 
+       STABS_DEBUG
+       DWARF_DEBUG
+
        /*
         * When something in the kernel is NOT compiled as a module, the
         * module cleanup code and data are put into these segments. Both
         * can then be thrown away, as cleanup code is never called unless
         * it's a module.
         */
-       /DISCARD/ : {
-               *(.exitcall.exit)
-               *(.discard)
-       }
-
-       STABS_DEBUG
-       DWARF_DEBUG
+       DISCARDS
 }
index d63cf914667de8c0cb327aaf182f2e83d19b42a9..866390feb6833002efc399a4f9cc6d7f32b31a3e 100644 (file)
@@ -171,13 +171,8 @@ SECTIONS
        }
        _end = . ;
 
-       /DISCARD/ : {
-               EXIT_TEXT
-               EXIT_DATA
-               *(.exitcall.exit)
-               *(.discard)
-       }
-
        STABS_DEBUG
        DWARF_DEBUG
+
+       DISCARDS
 }
index cb0248616d49d75ef1ef255210ac393b84b44018..37ecc5577a9ae8f406d64a9323d0fb0771c76dc7 100644 (file)
        __initramfs_end = .;
   }
 
-  /* Sections to be discarded */
-  /DISCARD/ : {
-       *(.exitcall.exit)
-  }
-
index 2916d6eadffd4ce92d9a922ab911b3b166e8590f..715a188c04729ca16f952ae312ec83015869ce76 100644 (file)
@@ -157,5 +157,5 @@ SECTIONS
 
   DWARF_DEBUG
 
-  /DISCARD/    : { *(.discard) }
+  DISCARDS
 }
index 1f8a622cabe1909ab237916462857dae3ea338ab..2ebd39765db85cee4db7331ec7841253f096ddea 100644 (file)
@@ -101,5 +101,5 @@ SECTIONS
 
   DWARF_DEBUG
 
-  /DISCARD/    : { *(.discard) }
+  DISCARDS
 }
index 367e878820418789055a6a2da48aa27350ada443..b600c843710bc3ce32f140a3754b292188ed3afe 100644 (file)
@@ -387,15 +387,12 @@ SECTIONS
                _end = .;
        }
 
-       /* Sections to be discarded */
-       /DISCARD/ : {
-               *(.exitcall.exit)
-               *(.eh_frame)
-               *(.discard)
-       }
-
         STABS_DEBUG
         DWARF_DEBUG
+
+       /* Sections to be discarded */
+       DISCARDS
+       /DISCARD/ : { *(.eh_frame) }
 }
 
 
index b1e24638acd7c3b2040cad8ea1487b85ec78fa8e..921b6ff3b6450e430f7b6613c139767280b39df9 100644 (file)
@@ -280,16 +280,6 @@ SECTIONS
     *(.ResetVector.text)
   }
 
-  /* Sections to be discarded */
-  /DISCARD/ :
-  {
-       *(.exit.literal)
-       EXIT_TEXT
-       EXIT_DATA
-        *(.exitcall.exit)
-       *(.discard)
-  }
-
   .xt.lit : { *(.xt.lit) }
   .xt.prop : { *(.xt.prop) }
 
@@ -322,4 +312,8 @@ SECTIONS
     *(.xt.lit)
     *(.gnu.linkonce.p*)
   }
+
+  /* Sections to be discarded */
+  DISCARDS
+  /DISCARD/ : { *(.exit.literal) }
 }
index c5c18ac878ab74d7f4fa5365cbddfa1e3f9bf3e4..ab8ea9b7741eb27014df31afa4d444f5f379bcd6 100644 (file)
  *     __bss_stop = .;
  *     _end = .;
  *
- *     /DISCARD/ : {
- *             EXIT_TEXT
- *             EXIT_DATA
- *             EXIT_CALL
- *     }
  *     STABS_DEBUG
  *     DWARF_DEBUG
+ *
+ *     DISCARDS                // must be the last
  * }
  *
  * [__init_begin, __init_end] is the init section that may be freed after init
 #define INIT_RAM_FS
 #endif
 
+/*
+ * Default discarded sections.
+ *
+ * Some archs want to discard exit text/data at runtime rather than
+ * link time due to cross-section references such as alt instructions,
+ * bug table, eh_frame, etc.  DISCARDS must be the last of output
+ * section definitions so that such archs put those in earlier section
+ * definitions.
+ */
 #define DISCARDS                                                       \
        /DISCARD/ : {                                                   \
        EXIT_TEXT                                                       \
        EXIT_DATA                                                       \
-       *(.exitcall.exit)                                               \
+       EXIT_CALL                                                       \
        *(.discard)                                                     \
        }