@@ -2,6 +2,7 @@ using Test
2
2
using BinaryBuilderBase
3
3
using BinaryBuilderBase: platform_dlext, platform_exeext, prefer_clang
4
4
using Pkg
5
+ using ObjectFile
5
6
6
7
@testset " Wrappers utilities" begin
7
8
@test nbits (Platform (" i686" , " linux" )) == 32
130
131
if lowercase (get (ENV , " BINARYBUILDER_FULL_SHARD_TEST" , " false" )) == " true"
131
132
@info (" Beginning full shard test... (this can take a while)" )
132
133
platforms = supported_platforms ()
134
+ elf_platforms = filter (p -> Sys. islinux (p) || Sys. isfreebsd (p), supported_platforms ())
135
+ win_platforms = filter (p -> Sys. iswindows (p), supported_platforms ())
133
136
else
134
137
platforms = (default_host_platform,)
138
+ elf_platforms = (default_host_platform,)
139
+ win_platforms = (Platform (" x86_64" , " windows" ),)
135
140
end
136
141
137
142
# Checks that the wrappers provide the correct C++ string ABI
153
158
end
154
159
end
155
160
161
+ # Checks that the compiler/linker include a build-id
162
+ # This is only available on ELF-based platforms
163
+ @testset " Compilation - Linux build-id note $(platform) - $(compiler) " for platform in elf_platforms, compiler in (" cc" , " gcc" , " clang" , " c++" , " g++" , " clang++" )
164
+ mktempdir () do dir
165
+ ur = preferred_runner ()(dir; platform= platform)
166
+ iobuff = IOBuffer ()
167
+ test_c = """
168
+ #include <stdlib.h>
169
+ int test(void) {
170
+ return 0;
171
+ }
172
+ """
173
+ test_script = """
174
+ set -e
175
+ cd /workspace
176
+ # Make sure setting `CCACHE` doesn't affect the compiler wrappers.
177
+ export CCACHE=pwned
178
+ export USE_CCACHE=false
179
+ echo '$(test_c) ' > test.c
180
+ # Build shared library
181
+ $(compiler) -shared test.c -o libtest.\$ {dlext}
182
+ """
183
+ cmd = ` /bin/bash -c "$(test_script) "`
184
+ @test run (ur, cmd, iobuff)
185
+
186
+ # Load the library file and test it for the build-id
187
+ lib_path = joinpath (dir, " libtest." * platform_dlext (platform))
188
+ lib = open (lib_path)
189
+ obj_handles = readmeta (lib)
190
+ obj = first (obj_handles)
191
+ secs = Sections (obj)
192
+
193
+ # The section must exist for the build-id to be present
194
+ @test ! isnothing (findfirst (s -> section_name (s) == " .note.gnu.build-id" , secs))
195
+ end
196
+ end
197
+
198
+ # Checks that Windows can include a build-id
199
+ @testset " Compilation - Windows build-id note $(platform) - $(compiler) " for platform in win_platforms, compiler in (" cc" , " gcc" , " clang" , " c++" , " g++" , " clang++" )
200
+ mktempdir () do dir
201
+ # Windows build-id support requires binutils 2.25, which is part of our GCC 5
202
+ ur = preferred_runner ()(dir; platform= platform, preferred_gcc_version= v " 5" )
203
+ iobuff = IOBuffer ()
204
+ test_c = """
205
+ #include <stdlib.h>
206
+ int test(void) {
207
+ return 0;
208
+ }
209
+ """
210
+ test_script = """
211
+ set -e
212
+ cd /workspace
213
+ # Make sure setting `CCACHE` doesn't affect the compiler wrappers.
214
+ export CCACHE=pwned
215
+ export USE_CCACHE=false
216
+ echo '$(test_c) ' > test.c
217
+ # Build shared library
218
+ $(compiler) -shared test.c -o libtest.\$ {dlext}
219
+ """
220
+ cmd = ` /bin/bash -c "$(test_script) "`
221
+ @test run (ur, cmd, iobuff)
222
+
223
+ # Load the library file and test it for the build-id
224
+ lib_path = joinpath (dir, " libtest." * platform_dlext (platform))
225
+ lib = open (lib_path)
226
+ obj_handles = readmeta (lib)
227
+ obj = first (obj_handles)
228
+ secs = Sections (obj)
229
+
230
+ # The section must exist for the build-id to be present
231
+ @test ! isnothing (findfirst (s -> section_name (s) == " .buildid" , secs))
232
+ end
233
+ end
234
+
156
235
# This tests only that compilers for all platforms can build and link simple C code
157
236
@testset " Compilation - $(platform) - $(compiler) " for platform in platforms, compiler in (" cc" , " gcc" , " clang" )
158
237
mktempdir () do dir
0 commit comments