[FREELDR] Introduce a MSVC "linker script" file that centralizes the commands for defining section-limit symbols, and the ordering and merging of PE sections, and the necessary CMake code to use it. (#1224)
As the MSVC linker alone doesn't permit such control, the file uses
ASM language (C can alternatively be used), together with extra linker
command-line switches.
It is pre-processed 3 times: first for generating the ASM code, second
for the C code and the third time for generating the linker response
file.
In our case, the ASM code defines the __bss_start__ and __bss_end__
symbols that allow us to find the limits of the .bss section (which is
by the way automatically appended to the .data section by the MSVC linker).
The C code is used to specify the list of linker switches that can be
passed through the `#pragma comment(linker, ...)' directive (the can be
alternatively specified in the linker response section).
Finally the linker response section contains all the linker switches
that cannot be specified with the `#pragma comment(linker, ...)'
directive.
Using all this we can recycle the BSS initialization code, that has been
written originally for GCC only, also for the MSVC builds.
Also, remove the outdated .text16 section merging.
2019-01-19 22:28:17 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
*** MSVC Linker Script File -- Sections specifications & layout ***
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
#error This file must be used only with the MSVC compiler and linker.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__LINKER__)
|
|
|
|
/*********************************\
|
|
|
|
** Linker response file **
|
|
|
|
\*********************************/
|
|
|
|
|
|
|
|
// /LAST:.bss
|
|
|
|
/LAST:.data
|
|
|
|
|
|
|
|
#elif !defined(_USE_ML)
|
|
|
|
/*********************************\
|
|
|
|
** C Linker #pragma directives **
|
|
|
|
\*********************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Notes about automatic LINK.EXE behaviour that cannot be changed:
|
|
|
|
*
|
|
|
|
* - If a .data section is present, the .bss section is appended to it in case
|
|
|
|
* both of these have either Initialized or Uninitialized data (which is the
|
|
|
|
* case, unless one has manually modified the attributes).
|
|
|
|
*
|
|
|
|
* - If the /DRIVER flag is NOT used, and if both the .rdata and the .edata
|
|
|
|
* sections (read-only data and exports, respectively) have the same
|
|
|
|
* attributes, the .edata section is appended to the .rdata section.
|
|
|
|
* Otherwise they are kept separated, unless an explicit /MERGE is used.
|
|
|
|
*/
|
|
|
|
|
2019-01-20 01:47:25 +00:00
|
|
|
#pragma comment(linker, "/SECTION:.text,ERW /SECTION:.data,RW /MERGE:.MBDATA=.text /MERGE:INIT=.text /MERGE:.edata=.rdata")
|
[FREELDR] Introduce a MSVC "linker script" file that centralizes the commands for defining section-limit symbols, and the ordering and merging of PE sections, and the necessary CMake code to use it. (#1224)
As the MSVC linker alone doesn't permit such control, the file uses
ASM language (C can alternatively be used), together with extra linker
command-line switches.
It is pre-processed 3 times: first for generating the ASM code, second
for the C code and the third time for generating the linker response
file.
In our case, the ASM code defines the __bss_start__ and __bss_end__
symbols that allow us to find the limits of the .bss section (which is
by the way automatically appended to the .data section by the MSVC linker).
The C code is used to specify the list of linker switches that can be
passed through the `#pragma comment(linker, ...)' directive (the can be
alternatively specified in the linker response section).
Finally the linker response section contains all the linker switches
that cannot be specified with the `#pragma comment(linker, ...)'
directive.
Using all this we can recycle the BSS initialization code, that has been
written originally for GCC only, also for the MSVC builds.
Also, remove the outdated .text16 section merging.
2019-01-19 22:28:17 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_USE_ML) // && !defined(__LINKER__)
|
|
|
|
/************************\
|
|
|
|
** ASM definitions **
|
|
|
|
\************************/
|
|
|
|
|
|
|
|
#include <asm.inc>
|
|
|
|
|
|
|
|
/*
|
|
|
|
#pragma bss_seg(".bss")
|
|
|
|
// __declspec(allocate(".bss"))
|
|
|
|
void* __bss_start__;
|
|
|
|
#pragma bss_seg()
|
|
|
|
*/
|
|
|
|
_BSS1 SEGMENT 'BSS' ALIAS('.bss')
|
|
|
|
PUBLIC __bss_start__
|
|
|
|
__bss_start__:
|
|
|
|
.long ?
|
|
|
|
_BSS1 ENDS
|
|
|
|
|
|
|
|
/*
|
|
|
|
#pragma bss_seg(".bss$ZZZ")
|
|
|
|
// __declspec(allocate(".bss$ZZZ"))
|
|
|
|
void* __bss_end__;
|
|
|
|
#pragma bss_seg()
|
|
|
|
*/
|
|
|
|
_BSS2 SEGMENT 'BSS' ALIAS('.bss$ZZZ')
|
|
|
|
PUBLIC __bss_end__
|
|
|
|
__bss_end__:
|
|
|
|
.long ?
|
|
|
|
_BSS2 ENDS
|
|
|
|
|
|
|
|
END
|
|
|
|
|
|
|
|
#elif !defined(__LINKER__)
|
|
|
|
/************************\
|
|
|
|
** C definitions **
|
|
|
|
\************************/
|
|
|
|
|
|
|
|
#endif
|