Commit 023bf6f1 authored by Tejun Heo's avatar Tejun Heo

linker script: unify usage of discard definition

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: default avatarTejun Heo <tj@kernel.org>
Acked-by: default avatarPaul Mundt <lethal@linux-sh.org>
Acked-by: default avatarMike Frysinger <vapier@gentoo.org>
Tested-by: default avatarMichal 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>
parent 1dcdd091
...@@ -134,14 +134,6 @@ SECTIONS ...@@ -134,14 +134,6 @@ SECTIONS
__bss_stop = .; __bss_stop = .;
_end = .; _end = .;
/* Sections to be discarded */
/DISCARD/ : {
EXIT_TEXT
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
.mdebug 0 : { .mdebug 0 : {
*(.mdebug) *(.mdebug)
} }
...@@ -151,4 +143,6 @@ SECTIONS ...@@ -151,4 +143,6 @@ SECTIONS
STABS_DEBUG STABS_DEBUG
DWARF_DEBUG DWARF_DEBUG
DISCARDS
} }
...@@ -124,15 +124,11 @@ SECTIONS ...@@ -124,15 +124,11 @@ SECTIONS
_end = .; _end = .;
} }
DWARF_DEBUG
/* When something in the kernel is NOT compiled as a module, the module /* 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 * 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. * thrown away, as cleanup code is never called unless it's a module.
*/ */
/DISCARD/ : { DISCARDS
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
DWARF_DEBUG
} }
...@@ -277,9 +277,5 @@ SECTIONS ...@@ -277,9 +277,5 @@ SECTIONS
DWARF_DEBUG DWARF_DEBUG
/DISCARD/ : DISCARDS
{
*(.exitcall.exit)
*(.discard)
}
} }
...@@ -140,13 +140,7 @@ SECTIONS ...@@ -140,13 +140,7 @@ SECTIONS
_end = .; _end = .;
__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; dram_end = dram_start + (CONFIG_ETRAX_DRAM_SIZE - __CONFIG_ETRAX_VMEM_SIZE)*1024*1024;
DISCARDS
} }
...@@ -178,7 +178,7 @@ SECTIONS ...@@ -178,7 +178,7 @@ SECTIONS
.comment 0 : { *(.comment) } .comment 0 : { *(.comment) }
/DISCARD/ : { *(.discard) } DISCARDS
} }
__kernel_image_size_no_bss = __bss_start - __kernel_image_start; __kernel_image_size_no_bss = __bss_start - __kernel_image_start;
...@@ -152,10 +152,6 @@ SECTIONS ...@@ -152,10 +152,6 @@ SECTIONS
__end = . ; __end = . ;
__ramstart = .; __ramstart = .;
} }
/DISCARD/ : {
*(.exitcall.exit)
*(.discard)
}
.romfs : .romfs :
{ {
*(.romfs*) *(.romfs*)
...@@ -166,4 +162,6 @@ SECTIONS ...@@ -166,4 +162,6 @@ SECTIONS
COMMAND_START = . - 0x200 ; COMMAND_START = . - 0x200 ;
__ramend = . ; __ramend = . ;
} }
DISCARDS
} }
...@@ -24,15 +24,14 @@ PHDRS { ...@@ -24,15 +24,14 @@ PHDRS {
} }
SECTIONS SECTIONS
{ {
/* Sections to be discarded */ /* unwind exit sections must be discarded before the rest of the
sections get included. */
/DISCARD/ : { /DISCARD/ : {
EXIT_TEXT
EXIT_DATA
*(.exitcall.exit)
*(.discard)
*(.IA_64.unwind.exit.text) *(.IA_64.unwind.exit.text)
*(.IA_64.unwind_info.exit.text) *(.IA_64.unwind_info.exit.text)
} *(.comment)
*(.note)
}
v = PAGE_OFFSET; /* this symbol is here to make debugging easier... */ v = PAGE_OFFSET; /* this symbol is here to make debugging easier... */
phys_start = _start - LOAD_OFFSET; phys_start = _start - LOAD_OFFSET;
...@@ -317,7 +316,7 @@ SECTIONS ...@@ -317,7 +316,7 @@ SECTIONS
.debug_funcnames 0 : { *(.debug_funcnames) } .debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) } .debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) } .debug_varnames 0 : { *(.debug_varnames) }
/* These must appear regardless of . */
/DISCARD/ : { *(.comment) } /* Default discards */
/DISCARD/ : { *(.note) } DISCARDS
} }
...@@ -120,14 +120,6 @@ SECTIONS ...@@ -120,14 +120,6 @@ SECTIONS
_end = . ; _end = . ;
/* Sections to be discarded */
/DISCARD/ : {
EXIT_TEXT
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
/* Stabs debugging sections. */ /* Stabs debugging sections. */
.stab 0 : { *(.stab) } .stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) } .stabstr 0 : { *(.stabstr) }
...@@ -136,4 +128,7 @@ SECTIONS ...@@ -136,4 +128,7 @@ SECTIONS
.stab.index 0 : { *(.stab.index) } .stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) } .stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) } .comment 0 : { *(.comment) }
/* Sections to be discarded */
DISCARDS
} }
...@@ -82,14 +82,6 @@ SECTIONS ...@@ -82,14 +82,6 @@ SECTIONS
_end = . ; _end = . ;
/* Sections to be discarded */
/DISCARD/ : {
EXIT_TEXT
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
/* Stabs debugging sections. */ /* Stabs debugging sections. */
.stab 0 : { *(.stab) } .stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) } .stabstr 0 : { *(.stabstr) }
...@@ -98,4 +90,7 @@ SECTIONS ...@@ -98,4 +90,7 @@ SECTIONS
.stab.index 0 : { *(.stab.index) } .stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) } .stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) } .comment 0 : { *(.comment) }
/* Sections to be discarded */
DISCARDS
} }
...@@ -77,14 +77,6 @@ __init_begin = .; ...@@ -77,14 +77,6 @@ __init_begin = .;
_end = . ; _end = . ;
/* Sections to be discarded */
/DISCARD/ : {
EXIT_TEXT
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
.crap : { .crap : {
/* Stabs debugging sections. */ /* Stabs debugging sections. */
*(.stab) *(.stab)
...@@ -97,4 +89,6 @@ __init_begin = .; ...@@ -97,4 +89,6 @@ __init_begin = .;
*(.note) *(.note)
} }
/* Sections to be discarded */
DISCARDS
} }
...@@ -184,13 +184,6 @@ SECTIONS { ...@@ -184,13 +184,6 @@ SECTIONS {
__init_end = .; __init_end = .;
} > INIT } > INIT
/DISCARD/ : {
EXIT_TEXT
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
.bss : { .bss : {
. = ALIGN(4); . = ALIGN(4);
_sbss = . ; _sbss = . ;
...@@ -201,5 +194,6 @@ SECTIONS { ...@@ -201,5 +194,6 @@ SECTIONS {
_end = . ; _end = . ;
} > BSS } > BSS
DISCARDS
} }
...@@ -163,5 +163,5 @@ SECTIONS { ...@@ -163,5 +163,5 @@ SECTIONS {
. = ALIGN(4096); . = ALIGN(4096);
_end = .; _end = .;
/DISCARD/ : { *(.discard) } DISCARDS
} }
...@@ -176,18 +176,6 @@ SECTIONS ...@@ -176,18 +176,6 @@ SECTIONS
_end = . ; _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. */ /* These mark the ABI of the kernel for debuggers. */
.mdebug.abi32 : { .mdebug.abi32 : {
KEEP(*(.mdebug.abi32)) KEEP(*(.mdebug.abi32))
...@@ -213,4 +201,14 @@ SECTIONS ...@@ -213,4 +201,14 @@ SECTIONS
*(.gptab.bss) *(.gptab.bss)
*(.gptab.sbss) *(.gptab.sbss)
} }
/* Sections to be discarded */
DISCARDS
/DISCARD/ : {
/* ABI crap starts here */
*(.MIPS.options)
*(.options)
*(.pdr)
*(.reginfo)
}
} }
...@@ -115,13 +115,10 @@ SECTIONS ...@@ -115,13 +115,10 @@ SECTIONS
. = ALIGN(PAGE_SIZE); . = ALIGN(PAGE_SIZE);
pg0 = .; pg0 = .;
/* Sections to be discarded */
/DISCARD/ : {
EXIT_CALL
*(.discard)
}
STABS_DEBUG STABS_DEBUG
DWARF_DEBUG DWARF_DEBUG
/* Sections to be discarded */
DISCARDS
} }
...@@ -237,10 +237,12 @@ SECTIONS ...@@ -237,10 +237,12 @@ SECTIONS
/* freed after init ends here */ /* freed after init ends here */
_end = . ; _end = . ;
STABS_DEBUG
.note 0 : { *(.note) }
/* Sections to be discarded */ /* Sections to be discarded */
DISCARDS
/DISCARD/ : { /DISCARD/ : {
*(.exitcall.exit)
*(.discard)
#ifdef CONFIG_64BIT #ifdef CONFIG_64BIT
/* temporary hack until binutils is fixed to not emit these /* temporary hack until binutils is fixed to not emit these
* for static binaries * for static binaries
...@@ -253,7 +255,4 @@ SECTIONS ...@@ -253,7 +255,4 @@ SECTIONS
*(.gnu.hash) *(.gnu.hash)
#endif #endif
} }
STABS_DEBUG
.note 0 : { *(.note) }
} }
...@@ -37,13 +37,6 @@ jiffies = jiffies_64 + 4; ...@@ -37,13 +37,6 @@ jiffies = jiffies_64 + 4;
#endif #endif
SECTIONS SECTIONS
{ {
/* Sections to be discarded. */
/DISCARD/ : {
*(.exitcall.exit)
*(.discard)
EXIT_DATA
}
. = KERNELBASE; . = KERNELBASE;
/* /*
...@@ -299,4 +292,7 @@ SECTIONS ...@@ -299,4 +292,7 @@ SECTIONS
. = ALIGN(PAGE_SIZE); . = ALIGN(PAGE_SIZE);
_end = . ; _end = . ;
PROVIDE32 (end = .); PROVIDE32 (end = .);
/* Sections to be discarded. */
DISCARDS
} }
...@@ -157,14 +157,10 @@ SECTIONS ...@@ -157,14 +157,10 @@ SECTIONS
_end = . ; _end = . ;
/* Sections to be discarded */
/DISCARD/ : {
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
/* Debugging sections. */ /* Debugging sections. */
STABS_DEBUG STABS_DEBUG
DWARF_DEBUG DWARF_DEBUG
/* Sections to be discarded */
DISCARDS
} }
...@@ -163,17 +163,14 @@ SECTIONS ...@@ -163,17 +163,14 @@ SECTIONS
_end = . ; _end = . ;
} }
STABS_DEBUG
DWARF_DEBUG
/* /*
* When something in the kernel is NOT compiled as a module, the * When something in the kernel is NOT compiled as a module, the
* module cleanup code and data are put into these segments. Both * module cleanup code and data are put into these segments. Both
* can then be thrown away, as cleanup code is never called unless * can then be thrown away, as cleanup code is never called unless
* it's a module. * it's a module.
*/ */
/DISCARD/ : { DISCARDS
*(.exitcall.exit)
*(.discard)
}
STABS_DEBUG
DWARF_DEBUG
} }
...@@ -171,13 +171,8 @@ SECTIONS ...@@ -171,13 +171,8 @@ SECTIONS
} }
_end = . ; _end = . ;
/DISCARD/ : {
EXIT_TEXT
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
STABS_DEBUG STABS_DEBUG
DWARF_DEBUG DWARF_DEBUG
DISCARDS
} }
...@@ -123,8 +123,3 @@ ...@@ -123,8 +123,3 @@
__initramfs_end = .; __initramfs_end = .;
} }
/* Sections to be discarded */
/DISCARD/ : {
*(.exitcall.exit)
}
...@@ -157,5 +157,5 @@ SECTIONS ...@@ -157,5 +157,5 @@ SECTIONS
DWARF_DEBUG DWARF_DEBUG
/DISCARD/ : { *(.discard) } DISCARDS
} }
...@@ -101,5 +101,5 @@ SECTIONS ...@@ -101,5 +101,5 @@ SECTIONS
DWARF_DEBUG DWARF_DEBUG
/DISCARD/ : { *(.discard) } DISCARDS
} }
...@@ -387,15 +387,12 @@ SECTIONS ...@@ -387,15 +387,12 @@ SECTIONS
_end = .; _end = .;
} }
/* Sections to be discarded */
/DISCARD/ : {
*(.exitcall.exit)
*(.eh_frame)
*(.discard)
}
STABS_DEBUG STABS_DEBUG
DWARF_DEBUG DWARF_DEBUG
/* Sections to be discarded */
DISCARDS
/DISCARD/ : { *(.eh_frame) }
} }
......
...@@ -280,16 +280,6 @@ SECTIONS ...@@ -280,16 +280,6 @@ SECTIONS
*(.ResetVector.text) *(.ResetVector.text)
} }
/* Sections to be discarded */
/DISCARD/ :
{
*(.exit.literal)
EXIT_TEXT
EXIT_DATA
*(.exitcall.exit)
*(.discard)
}
.xt.lit : { *(.xt.lit) } .xt.lit : { *(.xt.lit) }
.xt.prop : { *(.xt.prop) } .xt.prop : { *(.xt.prop) }
...@@ -322,4 +312,8 @@ SECTIONS ...@@ -322,4 +312,8 @@ SECTIONS
*(.xt.lit) *(.xt.lit)
*(.gnu.linkonce.p*) *(.gnu.linkonce.p*)
} }
/* Sections to be discarded */
DISCARDS
/DISCARD/ : { *(.exit.literal) }
} }
...@@ -35,13 +35,10 @@ ...@@ -35,13 +35,10 @@
* __bss_stop = .; * __bss_stop = .;
* _end = .; * _end = .;
* *
* /DISCARD/ : {
* EXIT_TEXT
* EXIT_DATA
* EXIT_CALL
* }
* STABS_DEBUG * STABS_DEBUG
* DWARF_DEBUG * DWARF_DEBUG
*
* DISCARDS // must be the last
* } * }
* *
* [__init_begin, __init_end] is the init section that may be freed after init * [__init_begin, __init_end] is the init section that may be freed after init
...@@ -629,11 +626,20 @@ ...@@ -629,11 +626,20 @@
#define INIT_RAM_FS #define INIT_RAM_FS
#endif #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 \ #define DISCARDS \
/DISCARD/ : { \ /DISCARD/ : { \
EXIT_TEXT \ EXIT_TEXT \
EXIT_DATA \ EXIT_DATA \
*(.exitcall.exit) \ EXIT_CALL \
*(.discard) \ *(.discard) \
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment