mirror of
https://github.com/dlang/dmd.git
synced 2025-05-04 00:53:20 +03:00
Issue 21488 - Always compile dmd with -fPIC on POSIX targets
This commit is contained in:
parent
d0406f3afe
commit
ffcc851a89
5 changed files with 21 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
||||||
[Environment32]
|
[Environment32]
|
||||||
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib32 -L--export-dynamic
|
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib32 -L--export-dynamic -fPIC
|
||||||
|
|
||||||
[Environment64]
|
[Environment64]
|
||||||
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib64 -L--export-dynamic
|
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib64 -L--export-dynamic -fPIC
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[Environment32]
|
[Environment32]
|
||||||
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib32 -L--export-dynamic
|
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib32 -L--export-dynamic -fPIC
|
||||||
|
|
||||||
[Environment64]
|
[Environment64]
|
||||||
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib64 -L--export-dynamic -fPIC
|
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib64 -L--export-dynamic -fPIC
|
||||||
|
|
20
src/build.d
20
src/build.d
|
@ -315,7 +315,7 @@ DFLAGS=%DFLAGS% -L/OPT:NOICF
|
||||||
{
|
{
|
||||||
enum confFile = "dmd.conf";
|
enum confFile = "dmd.conf";
|
||||||
enum conf = `[Environment32]
|
enum conf = `[Environment32]
|
||||||
DFLAGS=-I%@P%/../../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/{OS}/{BUILD}/32{exportDynamic}
|
DFLAGS=-I%@P%/../../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/{OS}/{BUILD}/32{exportDynamic} -fPIC
|
||||||
|
|
||||||
[Environment64]
|
[Environment64]
|
||||||
DFLAGS=-I%@P%/../../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/{OS}/{BUILD}/64{exportDynamic} -fPIC
|
DFLAGS=-I%@P%/../../../../../druntime/import -I%@P%/../../../../../phobos -L-L%@P%/../../../../../phobos/generated/{OS}/{BUILD}/64{exportDynamic} -fPIC
|
||||||
|
@ -1020,14 +1020,9 @@ void parseEnvironment()
|
||||||
// detect PIC
|
// detect PIC
|
||||||
version(Posix)
|
version(Posix)
|
||||||
{
|
{
|
||||||
// default to PIC on x86_64, use PIC=1/0 to en-/disable PIC.
|
// default to PIC if the host compiler supports, use PIC=1/0 to en-/disable PIC.
|
||||||
// Note that shared libraries and C files are always compiled with PIC.
|
// Note that shared libraries and C files are always compiled with PIC.
|
||||||
bool pic;
|
bool pic = true;
|
||||||
if (model == "64")
|
|
||||||
pic = true;
|
|
||||||
else if (model == "32")
|
|
||||||
pic = false;
|
|
||||||
|
|
||||||
const picValue = env.getDefault("PIC", "");
|
const picValue = env.getDefault("PIC", "");
|
||||||
switch (picValue)
|
switch (picValue)
|
||||||
{
|
{
|
||||||
|
@ -1037,6 +1032,15 @@ void parseEnvironment()
|
||||||
default:
|
default:
|
||||||
throw abortBuild(format("Variable 'PIC' should be '0', '1' or <empty> but got '%s'", picValue));
|
throw abortBuild(format("Variable 'PIC' should be '0', '1' or <empty> but got '%s'", picValue));
|
||||||
}
|
}
|
||||||
|
version (X86)
|
||||||
|
{
|
||||||
|
// https://issues.dlang.org/show_bug.cgi?id=20466
|
||||||
|
static if (__VERSION__ < 2090)
|
||||||
|
{
|
||||||
|
pragma(msg, "Warning: PIC will be off by default for this build of DMD because of Issue 20466!");
|
||||||
|
pic = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
env["PIC_FLAG"] = pic ? "-fPIC" : "";
|
env["PIC_FLAG"] = pic ? "-fPIC" : "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,14 +72,10 @@ else
|
||||||
endif
|
endif
|
||||||
export DMD=../generated/$(OS)/$(BUILD)/$(DMD_MODEL)/dmd
|
export DMD=../generated/$(OS)/$(BUILD)/$(DMD_MODEL)/dmd
|
||||||
|
|
||||||
# default to PIC on x86_64, use PIC=1/0 to en-/disable PIC.
|
# default to PIC, use PIC=1/0 to en-/disable PIC.
|
||||||
# Note that shared libraries and C files are always compiled with PIC.
|
# Note that shared libraries and C files are always compiled with PIC.
|
||||||
ifeq ($(PIC),)
|
ifeq ($(PIC),)
|
||||||
ifeq ($(MODEL),64) # x86_64
|
|
||||||
PIC:=1
|
PIC:=1
|
||||||
else
|
|
||||||
PIC:=0
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
ifeq ($(PIC),1)
|
ifeq ($(PIC),1)
|
||||||
export PIC_FLAG:=-fPIC
|
export PIC_FLAG:=-fPIC
|
||||||
|
|
12
test/run.d
12
test/run.d
|
@ -278,7 +278,7 @@ void ensureToolsExists(const string[string] env, const TestTool[] tools ...)
|
||||||
"-m"~env["MODEL"],
|
"-m"~env["MODEL"],
|
||||||
"-of"~targetBin,
|
"-of"~targetBin,
|
||||||
sourceFile
|
sourceFile
|
||||||
] ~ tool.extraArgs;
|
] ~ getPicFlags(env) ~ tool.extraArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
writefln("Executing: %-(%s %)", command);
|
writefln("Executing: %-(%s %)", command);
|
||||||
|
@ -518,15 +518,11 @@ string[string] getEnvironment()
|
||||||
auto druntimePath = environment.get("DRUNTIME_PATH", testPath(`../../druntime`));
|
auto druntimePath = environment.get("DRUNTIME_PATH", testPath(`../../druntime`));
|
||||||
auto phobosPath = environment.get("PHOBOS_PATH", testPath(`../../phobos`));
|
auto phobosPath = environment.get("PHOBOS_PATH", testPath(`../../phobos`));
|
||||||
|
|
||||||
// default to PIC on x86_64, use PIC=1/0 to en-/disable PIC.
|
// default to PIC, use PIC=1/0 to en-/disable PIC.
|
||||||
// Note that shared libraries and C files are always compiled with PIC.
|
// Note that shared libraries and C files are always compiled with PIC.
|
||||||
bool pic;
|
bool pic = true;
|
||||||
version(X86_64)
|
if (environment.get("PIC", "") == "0")
|
||||||
pic = true;
|
|
||||||
else version(X86)
|
|
||||||
pic = false;
|
pic = false;
|
||||||
if (environment.get("PIC", "0") == "1")
|
|
||||||
pic = true;
|
|
||||||
|
|
||||||
env["PIC_FLAG"] = pic ? "-fPIC" : "";
|
env["PIC_FLAG"] = pic ? "-fPIC" : "";
|
||||||
env["DFLAGS"] = "-I%s/import -I%s".format(druntimePath, phobosPath)
|
env["DFLAGS"] = "-I%s/import -I%s".format(druntimePath, phobosPath)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue