[Linux] Add support for PCK embedding section with non GNU-ld linkers.
(cherry picked from commit 625c4bdace
)
This commit is contained in:
parent
5bdad327c0
commit
2eb3139590
5 changed files with 14 additions and 40 deletions
|
@ -35,7 +35,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// For export templates, add a section; the exporter will patch it to enclose
|
// For export templates, add a section; the exporter will patch it to enclose
|
||||||
// the data appended to the executable (bundled PCK)
|
// the data appended to the executable (bundled PCK).
|
||||||
#ifndef TOOLS_ENABLED
|
#ifndef TOOLS_ENABLED
|
||||||
#if defined _MSC_VER
|
#if defined _MSC_VER
|
||||||
#pragma section("pck", read)
|
#pragma section("pck", read)
|
||||||
|
@ -44,7 +44,7 @@ __declspec(allocate("pck")) static char dummy[8] = { 0 };
|
||||||
// Dummy function to prevent LTO from discarding "pck" section.
|
// Dummy function to prevent LTO from discarding "pck" section.
|
||||||
extern "C" char *__cdecl pck_section_dummy_call() {
|
extern "C" char *__cdecl pck_section_dummy_call() {
|
||||||
return &dummy[0];
|
return &dummy[0];
|
||||||
};
|
}
|
||||||
#if defined _AMD64_
|
#if defined _AMD64_
|
||||||
#pragma comment(linker, "/include:pck_section_dummy_call")
|
#pragma comment(linker, "/include:pck_section_dummy_call")
|
||||||
#elif defined _X86_
|
#elif defined _X86_
|
||||||
|
|
|
@ -422,24 +422,6 @@ def configure(env):
|
||||||
if env["execinfo"]:
|
if env["execinfo"]:
|
||||||
env.Append(LIBS=["execinfo"])
|
env.Append(LIBS=["execinfo"])
|
||||||
|
|
||||||
if not env["tools"]:
|
|
||||||
import subprocess
|
|
||||||
import re
|
|
||||||
|
|
||||||
linker_version_str = subprocess.check_output(
|
|
||||||
[env.subst(env["LINK"]), "-Wl,--version"] + env.subst(env["LINKFLAGS"])
|
|
||||||
).decode("utf-8")
|
|
||||||
gnu_ld_version = re.search(r"^GNU ld [^$]*(\d+\.\d+)$", linker_version_str, re.MULTILINE)
|
|
||||||
if not gnu_ld_version:
|
|
||||||
print(
|
|
||||||
"Warning: Creating export template binaries enabled for PCK embedding is currently only supported with GNU ld, not gold, LLD or mold."
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
if float(gnu_ld_version.group(1)) >= 2.30:
|
|
||||||
env.Append(LINKFLAGS=["-T", "platform/x11/pck_embed.ld"])
|
|
||||||
else:
|
|
||||||
env.Append(LINKFLAGS=["-T", "platform/x11/pck_embed.legacy.ld"])
|
|
||||||
|
|
||||||
# Link those statically for portability
|
# Link those statically for portability
|
||||||
if env["use_static_cpp"]:
|
if env["use_static_cpp"]:
|
||||||
env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"])
|
env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"])
|
||||||
|
|
|
@ -36,6 +36,18 @@
|
||||||
#include "main/main.h"
|
#include "main/main.h"
|
||||||
#include "os_x11.h"
|
#include "os_x11.h"
|
||||||
|
|
||||||
|
// For export templates, add a section; the exporter will patch it to enclose
|
||||||
|
// the data appended to the executable (bundled PCK).
|
||||||
|
#if !defined(TOOLS_ENABLED) && defined(__GNUC__)
|
||||||
|
static const char dummy[8] __attribute__((section("pck"), used)) = { 0 };
|
||||||
|
|
||||||
|
// Dummy function to prevent LTO from discarding "pck" section.
|
||||||
|
extern "C" const char *pck_section_dummy_call() __attribute__((used));
|
||||||
|
extern "C" const char *pck_section_dummy_call() {
|
||||||
|
return &dummy[0];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
OS_X11 os;
|
OS_X11 os;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
SECTIONS
|
|
||||||
{
|
|
||||||
/* Add a zero-sized section; the exporter will patch it to enclose the data appended to the executable (embedded PCK) */
|
|
||||||
pck 0 (INFO) :
|
|
||||||
{
|
|
||||||
/* binutils >= 2.30 allow it being zero-sized, but needs something between the braces to keep the section */
|
|
||||||
. = ALIGN(8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
INSERT AFTER .rodata;
|
|
|
@ -1,10 +0,0 @@
|
||||||
SECTIONS
|
|
||||||
{
|
|
||||||
/* The exporter will patch this section to enclose the data appended to the executable (embedded PCK) */
|
|
||||||
pck 0 (INFO) : AT ( ADDR (.rodata) + SIZEOF (.rodata) )
|
|
||||||
{
|
|
||||||
/* binutils < 2.30 need some actual content for the linker not to discard the section */
|
|
||||||
BYTE(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
INSERT AFTER .rodata;
|
|
Loading…
Reference in a new issue