Skip to content

Commit 3da9203

Browse files
Merge branch 'mr/encode-default-target-at-build-time' into 'master'
Encode the default target at build time See merge request eng/toolchain/gnat-llvm!360
2 parents 0f1d3a0 + a95d32c commit 3da9203

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

llvm-interface/Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ GEN_IL_FILES = nmake.adb nmake.ads \
7171
seinfo.ads sinfo-nodes.ads sinfo-nodes.adb \
7272
einfo-entities.ads einfo-entities.adb
7373

74+
target=$(shell gcc -dumpmachine)
75+
llvm_target=$(shell clang -dumpmachine)
76+
7477
setup:
7578
$(MKDIR) obj obj-tools/libgnat bin gnat_src/vast
7679
for f in `cd $(GNAT_SRC); ls gen_il*.ad? xutil.ad? *-tmpl xoscons.adb xsnamest.adb`; \
@@ -86,21 +89,22 @@ setup:
8689
done
8790
./check_for_LLVM_aliasing_bug.sh
8891
./check_for_llvm_apis.sh "$(LLVM_CONFIG)"
92+
./configure_default_target.sh "$(llvm_target)"
8993

9094
build: setup force
9195
$(GPRBUILD) -Pgnat_llvm -j$(PROCS) \
9296
-largs $(LDFLAGS) -cargs:c++ $(ALL_CXXFLAGS)
93-
$(GPRBUILD) -Ptools -j$(PROCS) -largs $(LDFLAGS)
97+
$(GPRBUILD) -Ptools -j$(PROCS)
9498

9599
build-uninit: setup force
96100
$(GPRBUILD) -XBuild=Uninitialized -Pgnat_llvm -j$(PROCS) \
97101
-largs $(LDFLAGS) -cargs:c++ $(ALL_CXXFLAGS)
98-
$(GPRBUILD) -Ptools -j$(PROCS) -largs $(LDFLAGS)
102+
$(GPRBUILD) -Ptools -j$(PROCS)
99103

100104
build-opt: setup force
101105
$(GPRBUILD) $(GPROPT) -Pgnat_llvm -j$(PROCS) \
102106
-largs $(LDFLAGS) -cargs:c++ $(ALL_CXXFLAGS)
103-
$(GPRBUILD) $(GPROPT) -Ptools -j$(PROCS) -largs $(LDFLAGS)
107+
$(GPRBUILD) $(GPROPT) -Ptools -j$(PROCS)
104108

105109
# Target for building with coverage instrumentation.
106110
build-cov: setup force
@@ -186,8 +190,6 @@ clean:
186190
# Note some of these target(.*) variables are used in gnat_src's Makefiles.
187191
# Renaming them will lead to runtime compilation errors.
188192

189-
target=$(shell gcc -dumpmachine)
190-
191193
target_list=$(filter-out gnu,$(subst -, ,$(target)))
192194
target_cpu=$(word 1,$(target_list))
193195

@@ -207,8 +209,6 @@ else
207209
make gnatlib-automated
208210
endif
209211

210-
llvm_target=$(shell clang -dumpmachine)
211-
212212
RTSBASE=rts-native
213213
RTS=$(pwd)/lib/gnat-llvm/$(llvm_target)/$(RTSBASE)
214214
RTSDIR=$(RTS)/adainclude

llvm-interface/check_for_LLVM_aliasing_bug.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ else
119119
BUG=True
120120
echo "using LLVM with the aliasing bug, will pessimize slightly the optimized code"
121121
fi
122-
cat << EOF > obj/gnatllvm-aliasing-params.ads
122+
cat << EOF > obj/tmp-gnatllvm-aliasing-params.ads
123123
package GNATLLVM.Aliasing.Params is
124124
LLVM_Struct_Tag_Bug : constant Boolean := $BUG;
125125
end GNATLLVM.Aliasing.Params;
126126
EOF
127+
128+
./move-if-change obj/tmp-gnatllvm-aliasing-params.ads obj/gnatllvm-aliasing-params.ads
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
default_target="$1"
6+
7+
cat << EOF > obj/tmp-options-target.ads
8+
package Options.Target is
9+
Default_Target_Triple : constant String := "$default_target";
10+
end Options.Target;
11+
EOF
12+
13+
./move-if-change obj/tmp-options-target.ads obj/options-target.ads

llvm-interface/gcc_wrapper.adb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ with Ada.Command_Line; use Ada.Command_Line;
3030
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
3131
with GNAT.OS_Lib; use GNAT.OS_Lib;
3232
with GNATLLVM;
33-
34-
with LLVM.Target_Machine; use LLVM.Target_Machine;
33+
with Options.Target; use Options.Target;
3534

3635
with Gnatvsn; use Gnatvsn;
3736

@@ -207,7 +206,7 @@ procedure GCC_Wrapper is
207206
Suffix : String_Access := Get_Target_Executable_Suffix;
208207
Result : constant String :=
209208
Executable_Location & "libexec/gnat-llvm/" &
210-
Get_Default_Target_Triple & "/bin/" & Exec;
209+
Default_Target_Triple & "/bin/" & Exec;
211210
Is_Exec : constant Boolean :=
212211
Is_Executable_File (Result & Suffix.all);
213212

@@ -248,7 +247,7 @@ begin
248247

249248
elsif Arg = "-dumpmachine" then
250249

251-
Put_Line (Get_Default_Target_Triple);
250+
Put_Line (Default_Target_Triple);
252251
OS_Exit (0);
253252

254253
elsif Arg = "--version" then

llvm-interface/gnatllvm-codegen.ads

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
-- of the license. --
1616
------------------------------------------------------------------------------
1717

18-
with Options; use Options;
18+
with Options; use Options;
19+
with Options.Target; use Options.Target;
1920

2021
package GNATLLVM.Codegen is
2122

@@ -49,7 +50,7 @@ package GNATLLVM.Codegen is
4950
-- Features to enable or disable for this target
5051

5152
Target_Triple : String_Access :=
52-
new String'(Get_Default_Target_Triple);
53+
new String'(Default_Target_Triple);
5354
-- Name of the target for this compilation
5455

5556
Normalized_Target_Triple : String_Access := null;

llvm-interface/sdefault.adb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
-- This package body provides the llvm-gnat1 implementation of the routines
2626
-- that locate the Ada library source and object directories.
2727

28-
with LLVM.Target_Machine; use LLVM.Target_Machine;
29-
3028
with Options; use Options;
29+
with Options.Target; use Options.Target;
3130
with Osint; use Osint;
3231

3332
package body Sdefault is
@@ -42,7 +41,7 @@ package body Sdefault is
4241
return Relocate_Path ("/PREFIX",
4342
(if CCG then "/PREFIX/lib/rts-ccg/adainclude"
4443
else "/PREFIX/lib/gnat-llvm/" &
45-
Get_Default_Target_Triple &
44+
Default_Target_Triple &
4645
"/rts-native/adainclude"));
4746
end Include_Dir_Default_Name;
4847

@@ -55,7 +54,7 @@ package body Sdefault is
5554
return Relocate_Path ("/PREFIX",
5655
(if CCG then "/PREFIX/lib/rts-ccg/adalib"
5756
else "/PREFIX/lib/gnat-llvm/" &
58-
Get_Default_Target_Triple &
57+
Default_Target_Triple &
5958
"/rts-native/adalib"));
6059
end Object_Dir_Default_Name;
6160

@@ -68,7 +67,7 @@ package body Sdefault is
6867
return Relocate_Path ("/PREFIX",
6968
(if CCG then "/PREFIX/lib/"
7069
else "/PREFIX/lib/gnat-llvm/" &
71-
Get_Default_Target_Triple & "//"));
70+
Default_Target_Triple & "//"));
7271
end Search_Dir_Prefix;
7372

7473
-----------------
@@ -77,7 +76,7 @@ package body Sdefault is
7776

7877
function Target_Name return String_Ptr is
7978
begin
80-
return new String'(Get_Default_Target_Triple);
79+
return new String'(Default_Target_Triple);
8180
end Target_Name;
8281

8382
end Sdefault;

llvm-interface/tools.gpr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
with "gnat_llvm_c";
22

33
project Tools is
4-
for Source_Dirs use
5-
(".", "obj", "gnat_src", "../llvm-bindings/adainclude");
4+
for Source_Dirs use (".", "obj", "gnat_src");
65
for Object_Dir use "obj";
76
for Exec_Dir use "bin";
87
for Languages use ("Ada");

0 commit comments

Comments
 (0)