forked from zephyrproject-rtos/picolibc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
1648 lines (1434 loc) · 64.4 KB
/
meson.build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# SPDX-License-Identifier: BSD-3-Clause
#
# Copyright © 2019-2021 Keith Packard
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
project('picolibc', 'c',
default_options: [
'buildtype=minsize',
'debug=true',
'c_std=c18',
'b_staticpic=false',
'warning_level=2',
],
license : 'BSD',
meson_version : '>= 0.53',
version: '1.8.6'
)
targets = []
fs = import('fs')
cc = meson.get_compiler('c')
# Find the compiler installation directory by parsing the output of
# cc -print-search-dirs
cc_install_dir = ''
foreach _line : run_command(cc.cmd_array() + ['-print-search-dirs'], check : false).stdout().split('\n')
if _line.startswith('install: ')
if meson.version().version_compare('>=0.56')
# trim off the leading 'install: '
cc_install_dir = _line.substring(9)
else
cc_install_dir = run_command(['expr', _line, ':', 'install: *\(.*\)'], check : false).stdout().split('\n')[0]
endif
endif
endforeach
# these options are required for all C compiler operations, including
# detecting many C compiler features, as we cannot expect there
# to be a working C library on the system.
core_c_args = []
if not get_option('use-stdlib')
core_c_args += cc.get_supported_arguments(['-nostdlib'])
endif
# Find the picolibc name for the host cpu. Provide
# for some common aliases
cpu_family_aliases = {
# aarch64
'arm64' : 'aarch64',
# arc
'arc64' : 'arc',
# cris
'crisv32' : 'cris',
# m68hc11
'm6811' : 'm68hc11',
'm6812' : 'm68hc11',
'm68hc12' : 'm68hc11',
# m68k
'fido' : 'm68k',
# m88k
'm88110' : 'm88k',
# Microblaze
'microblazeel' : 'microblaze',
# or1k
'or1knd': 'or1k',
# powerpc
'powerpc64' : 'powerpc',
'ppc64' : 'powerpc',
'ppc64le' : 'powerpc',
# riscv
'riscv32' : 'riscv',
'riscv64' : 'riscv',
# sparc
'sparc64' : 'sparc',
# x86
'amd64' : 'x86',
'i486' : 'x86',
'i586' : 'x86',
'i686' : 'x86',
'x86_64' : 'x86',
}
# Check for an alias, default to provided name
host_cpu_family = cpu_family_aliases.get(host_machine.cpu_family(), host_machine.cpu_family())
# Make sure we have meson build support for the machine-specific files
if not fs.is_file('newlib/libc/machine' / host_cpu_family / 'meson.build')
message = '''
Unsupported architecture: "@0@"
Read the Supported Architectures section in README.md
to learn how to add a new architecture.
'''
error(message.format(host_cpu_family))
endif
# Find out about float types
long_double_code = '''
#include <float.h>
#ifndef __LDBL_MANT_DIG__
#error No long double support in float.h
#endif
long double test(void)
{
long double ld = 0.0L;
return ld;
}
'''
have_long_double = cc.compiles(long_double_code, name : 'long double check', args: core_c_args)
enable_multilib = get_option('multilib')
multilib_list = get_option('multilib-list')
multilib_exclude = get_option('multilib-exclude')
enable_picolib = get_option('picolib')
enable_picocrt = get_option('picocrt')
enable_picocrt_lib = get_option('picocrt-lib')
enable_semihost = get_option('semihost')
enable_tests = get_option('tests')
enable_native_tests = get_option('native-tests')
tests_enable_stack_protector = get_option('tests-enable-stack-protector')
tests_enable_full_malloc_stress = get_option('tests-enable-full-malloc-stress')
tests_enable_posix_io = get_option('tests-enable-posix-io')
have_alias_attribute_option = get_option('have-alias-attribute')
have_format_attribute_option = get_option('have-format-attribute')
have_weak_attribute_option = get_option('have-weak-attribute')
newlib_iconv_encodings = get_option('newlib-iconv-encodings')
newlib_iconv_encodings_exclude = get_option('newlib-iconv-encodings-exclude')
newlib_iconv_from_encodings = get_option('newlib-iconv-from-encodings')
newlib_iconv_to_encodings = get_option('newlib-iconv-to-encodings')
newlib_iconv_external_ccs = get_option('newlib-iconv-external-ccs')
newlib_atexit_dynamic_alloc = get_option('newlib-atexit-dynamic-alloc')
newlib_nano_malloc = get_option('newlib-nano-malloc')
lite_exit = get_option('lite-exit')
newlib_elix_level = get_option('newlib-elix-level')
c_args = ['-include', '@0@/@1@'.format(meson.current_build_dir(), 'picolibc.h')] + core_c_args
native_c_args = ['-DNO_NEWLIB']
if get_option('profile')
c_args += ['-pg', '-no-pie']
endif
if get_option('freestanding')
c_args += ['-ffreestanding']
endif
# Disable ssp and fortify source while building picolibc (it's enabled
# by default by the ubuntu native compiler)
c_flags = cc.get_supported_arguments(['-fno-common', '-frounding-math', '-fsignaling-nans',
'-Wno-unsupported-floating-point-opt', '-fno-stack-protector',
'-fno-builtin-copysignl'])
c_sanitize_bounds_flags = cc.get_supported_arguments(['-fsanitize=bounds'])
c_sanitize_trap_flags = cc.get_supported_arguments(['-fsanitize-undefined-trap-on-error'])
c_sanitize_no_trap_flags = cc.get_supported_arguments(['-fno-sanitize-undefined-trap-on-error', '-static-libubsan'])
have_ubsan = c_sanitize_bounds_flags != []
c_args += c_flags
native_c_args += c_flags
sanitize_bounds = get_option('sanitize-bounds')
sanitize_trap_on_error = get_option('sanitize-trap-on-error')
if sanitize_bounds
if not have_ubsan
error('sanitize-bounds option selected but -fsanitize=bounds is not supported')
endif
c_args += c_sanitize_bounds_flags
native_c_args += c_sanitize_bounds_flags
if sanitize_trap_on_error
c_args += c_sanitize_trap_flags
else
c_args += c_sanitize_no_trap_flags
endif
endif
if cc.symbols_have_underscore_prefix()
global_prefix = '_'
else
global_prefix = ''
endif
fast_strcmp = get_option('fast-strcmp')
newlib_mb = get_option('newlib-mb')
newlib_locale_info = get_option('newlib-locale-info')
newlib_obsolete_math = get_option('newlib-obsolete-math')
newlib_obsolete_math_float = get_option('newlib-obsolete-math-float')
newlib_obsolete_math_double = get_option('newlib-obsolete-math-double')
sysroot_install = get_option('sysroot-install')
system_libc = get_option('system-libc')
prefix = get_option('prefix')
nm = find_program('nm', required : false)
check_duplicate_names = nm.found()
if nm.found()
duplicate_names = find_program('scripts/duplicate-names', required : true)
endif
# Select exit code
picoexit = get_option('picoexit')
# Shared stdio options
io_long_long = get_option('io-long-long')
newlib_io_long_long = get_option('newlib-io-long-long')
if newlib_io_long_long != 'auto'
io_long_long = newlib_io_long_long == 'true'
endif
io_c99_formats = get_option('io-c99-formats')
newlib_io_c99_formats = get_option('newlib-io-c99-formats')
if newlib_io_c99_formats != 'auto'
io_c99_formats = newlib_io_c99_formats == 'true'
endif
io_pos_args = get_option('io-pos-args')
newlib_io_pos_args = get_option('newlib-io-pos-args')
if newlib_io_pos_args != 'auto'
io_pos_args = newlib_io_pos_args == 'true'
endif
# Select stdio implementation
tinystdio = get_option('tinystdio')
has_link_defsym = meson.get_cross_property('has_link_defsym',
cc.has_link_argument('-Wl,--defsym=' + 'start=0') or
cc.has_link_argument('-Wl,--defsym=' + '_start=0') or
cc.has_link_argument('-Wl,--defsym=' + '__start=0') or
cc.has_link_argument('-Wl,--defsym=' + '___start=0') )
has_link_alias = meson.get_cross_property('has_link_alias', cc.has_link_argument('-Wl,-alias,' + global_prefix + 'main,testalias'))
lib_gcc = meson.get_cross_property('libgcc', '-lgcc')
# tinystdio options
posix_console = tinystdio and get_option('posix-console')
posix_io = tinystdio and (get_option('posix-io') or posix_console)
io_float_exact = not tinystdio or get_option('io-float-exact')
atomic_ungetc = tinystdio and get_option('atomic-ungetc')
format_default = get_option('format-default')
printf_aliases = get_option('printf-aliases')
io_percent_b = tinystdio and get_option('io-percent-b')
io_long_double = get_option('io-long-double') or get_option('newlib-io-long-double')
printf_small_ultoa = tinystdio and get_option('printf-small-ultoa')
minimal_io_long_long = tinystdio and get_option('minimal-io-long-long')
fast_bufio = tinystdio and get_option('fast-bufio')
if printf_aliases
double_printf_compile_args=['-DPICOLIBC_DOUBLE_PRINTF_SCANF']
float_printf_compile_args=['-DPICOLIBC_FLOAT_PRINTF_SCANF']
llong_printf_compile_args=['-DPICOLIBC_LONG_LONG_PRINTF_SCANF']
int_printf_compile_args=['-DPICOLIBC_INTEGER_PRINTF_SCANF']
min_printf_compile_args=['-DPICOLIBC_MINIMAL_PRINTF_SCANF']
else
double_printf_compile_args=[]
float_printf_compile_args=[]
llong_printf_compile_args=[]
int_printf_compile_args=[]
min_printf_compile_args=[]
endif
double_printf_link_args=double_printf_compile_args
float_printf_link_args=float_printf_compile_args
llong_printf_link_args=llong_printf_compile_args
int_printf_link_args=int_printf_compile_args
min_printf_link_args=min_printf_compile_args
if tinystdio and printf_aliases
vfprintf_symbol = global_prefix + 'vfprintf'
__d_vfprintf_symbol = global_prefix + '__d_vfprintf'
__f_vfprintf_symbol = global_prefix + '__f_vfprintf'
__l_vfprintf_symbol = global_prefix + '__l_vfprintf'
__i_vfprintf_symbol = global_prefix + '__i_vfprintf'
__m_vfprintf_symbol = global_prefix + '__m_vfprintf'
vfscanf_symbol = global_prefix + 'vfscanf'
__d_vfscanf_symbol = global_prefix + '__d_vfscanf'
__f_vfscanf_symbol = global_prefix + '__f_vfscanf'
__l_vfscanf_symbol = global_prefix + '__l_vfscanf'
__i_vfscanf_symbol = global_prefix + '__i_vfscanf'
__m_vfscanf_symbol = global_prefix + '__m_vfscanf'
if has_link_defsym
if format_default != 'double'
double_printf_link_args += '-Wl,--defsym=' + vfprintf_symbol + '=' + __d_vfprintf_symbol
double_printf_link_args += '-Wl,--defsym=' + vfscanf_symbol + '=' + __d_vfscanf_symbol
endif
if format_default != 'float'
float_printf_link_args += '-Wl,--defsym=' + vfprintf_symbol + '=' + __f_vfprintf_symbol
float_printf_link_args += '-Wl,--defsym=' + vfscanf_symbol + '=' + __f_vfscanf_symbol
endif
if format_default != 'long-long'
llong_printf_link_args += '-Wl,--defsym=' + vfprintf_symbol + '=' + __l_vfprintf_symbol
llong_printf_link_args += '-Wl,--defsym=' + vfscanf_symbol + '=' + __l_vfscanf_symbol
endif
if format_default != 'integer'
int_printf_link_args += '-Wl,--defsym=' + vfprintf_symbol + '=' + __i_vfprintf_symbol
int_printf_link_args += '-Wl,--defsym=' + vfscanf_symbol + '=' + __i_vfscanf_symbol
endif
if format_default != 'minimal'
min_printf_link_args += '-Wl,--defsym=' + vfprintf_symbol + '=' + __m_vfprintf_symbol
min_printf_link_args += '-Wl,--defsym=' + vfscanf_symbol + '=' + __m_vfscanf_symbol
endif
elif has_link_alias
if format_default == 'double'
float_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __d_vfprintf_symbol
float_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __d_vfscanf_symbol
llong_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __d_vfprintf_symbol
llong_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __d_vfscanf_symbol
int_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __d_vfprintf_symbol
int_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __d_vfscanf_symbol
min_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __d_vfprintf_symbol
min_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __d_vfscanf_symbol
endif
if format_default == 'float'
double_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __f_vfprintf_symbol
double_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __f_vfscanf_symbol
llong_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __f_vfprintf_symbol
llong_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __f_vfscanf_symbol
int_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __f_vfprintf_symbol
int_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __f_vfscanf_symbol
min_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __f_vfprintf_symbol
min_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __f_vfscanf_symbol
endif
if format_default == 'long-long'
double_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __l_vfprintf_symbol
double_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __l_vfscanf_symbol
float_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __l_vfprintf_symbol
float_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __l_vfscanf_symbol
int_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __l_vfprintf_symbol
int_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __l_vfscanf_symbol
min_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __l_vfprintf_symbol
min_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __l_vfscanf_symbol
endif
if format_default == 'integer'
double_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __i_vfprintf_symbol
double_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __i_vfscanf_symbol
float_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __i_vfprintf_symbol
float_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __i_vfscanf_symbol
llong_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __i_vfprintf_symbol
llong_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __i_vfscanf_symbol
min_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __i_vfprintf_symbol
min_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __i_vfscanf_symbol
endif
if format_default == 'minimal'
double_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __m_vfprintf_symbol
double_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __m_vfscanf_symbol
float_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __m_vfprintf_symbol
float_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __m_vfscanf_symbol
llong_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __m_vfprintf_symbol
llong_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __m_vfscanf_symbol
int_printf_link_args += '-Wl,-alias,' + vfprintf_symbol + ',' + __m_vfprintf_symbol
int_printf_link_args += '-Wl,-alias,' + vfscanf_symbol + ',' + __m_vfscanf_symbol
endif
if format_default != 'double'
double_printf_link_args += '-Wl,-alias,' + __d_vfprintf_symbol + ',' + vfprintf_symbol
double_printf_link_args += '-Wl,-alias,' + __d_vfscanf_symbol + ',' + vfscanf_symbol
endif
if format_default != 'float'
float_printf_link_args += '-Wl,-alias,' + __f_vfprintf_symbol + ',' + vfprintf_symbol
float_printf_link_args += '-Wl,-alias,' + __f_vfscanf_symbol + ',' + vfscanf_symbol
endif
if format_default != 'long-long'
llong_printf_link_args += '-Wl,-alias,' + __l_vfprintf_symbol + ',' + vfprintf_symbol
llong_printf_link_args += '-Wl,-alias,' + __l_vfscanf_symbol + ',' + vfscanf_symbol
endif
if format_default != 'integer'
int_printf_link_args += '-Wl,-alias,' + __i_vfprintf_symbol + ',' + vfprintf_symbol
int_printf_link_args += '-Wl,-alias,' + __i_vfscanf_symbol + ',' + vfscanf_symbol
endif
if format_default != 'minimal'
min_printf_link_args += '-Wl,-alias,' + __m_vfprintf_symbol + ',' + vfprintf_symbol
min_printf_link_args += '-Wl,-alias,' + __m_vfscanf_symbol + ',' + vfscanf_symbol
endif
else
if enable_tests
# If the alias flag is not supported and we are building tests, emit an
# error here to avoid surprising test failures.
error('Symbol alias linker flag not supported - printf tests will fail!')
endif
endif
endif
# A bunch of newlib-stdio only options
newlib_global_stdio_streams = get_option('newlib-global-stdio-streams')
newlib_fvwrite_in_streamio = get_option('newlib-fvwrite-in-streamio')
newlib_fseek_optimization = get_option('newlib-fseek-optimization')
newlib_nano_formatted_io = get_option('newlib-nano-formatted-io')
newlib_io_float = get_option('newlib-io-float')
newlib_stdio64 = get_option('newlib-stdio64')
newlib_wide_orient = get_option('newlib-wide-orient')
newlib_have_fcntl = get_option('newlib-have-fcntl')
# Check for a bunch of newlib-stdio only options and complain
# if they are selected while using tinystdio
if tinystdio
if newlib_io_float
error('tinystdio uses a run-time mechanism to select floating point io (newlib-io-float)')
endif
if newlib_global_stdio_streams
error('tinystdio always has (reentrant) global stdio streams (newlib-global-stdio-streams)')
endif
if newlib_fvwrite_in_streamio
error('tinystdio has no fvwrite support (newlib-fvwrite-in-streamio)')
endif
if newlib_fseek_optimization
error('tinystdio has no fseek support (newlib-fseek-optimization)')
endif
if newlib_nano_formatted_io
error('tinystdio uses a run-time mechanism to select smaller printf code (newlib-nano-formatted-io)')
endif
if newlib_wide_orient
error('tinystdio does not support the wide-orient option (newlib-wide-orient)')
endif
else
if posix_console
error('newlib stdio does not support the posix-console option (posix-console)')
endif
if io_pos_args
error('newlib stdio has bugs with positional arguments (io-pos-args)')
endif
endif
if host_cpu_family == ''
host_cc_machine=run_command(cc.cmd_array() + ['-dumpmachine'], check : true).stdout().strip().split('-')
host_cpu_family=host_cc_machine[0]
message('Computed host_cpu_family as ' + host_cpu_family)
endif
if have_alias_attribute_option == 'auto'
have_alias_attribute = cc.has_function_attribute('alias')
else
have_alias_attribute = have_alias_attribute_option == 'true'
endif
if have_format_attribute_option == 'auto'
have_format_attribute = cc.has_function_attribute('format')
else
have_format_attribute = have_format_attribute_option == 'true'
endif
if have_weak_attribute_option == 'auto'
have_weak_attribute = cc.has_function_attribute('weak')
else
have_weak_attribute = have_weak_attribute_option == 'true'
endif
tls_model_spec = ''
thread_local_storage = false
thread_local_storage_option = get_option('thread-local-storage')
have_picolibc_tls_api = fs.is_file('newlib/libc/picolib/machine' / host_cpu_family / 'tls.c')
if thread_local_storage_option == 'auto' or thread_local_storage_option == 'picolibc'
# We assume that _set_tls() is defined in the arch specific tls.c
if thread_local_storage_option == 'auto' or have_picolibc_tls_api
thread_local_storage = not cc.has_function('__emutls_get_address', args: core_c_args + [lib_gcc])
endif
else
thread_local_storage = get_option('thread-local-storage') == 'true'
endif
if thread_local_storage
tls_model_spec = '%{!ftls-model:-ftls-model=' + get_option('tls-model') + '}'
endif
if sysroot_install
sysroot = run_command(cc.cmd_array() + ['-print-sysroot'], check : true).stdout().split('\n')[0]
if sysroot != ''
specs_prefix_format = '%R/@0@'
else
sysroot = cc_install_dir + '../../../..'
specs_prefix_format = '%:getenv(GCC_EXEC_PREFIX ../../@0@)'
endif
if not get_option('sysroot-install-skip-checks')
if sysroot == ''
error('sysroot install requested, but compiler has no sysroot')
endif
if not fs.is_samepath(sysroot, prefix)
error('sysroot install requires --prefix=' + sysroot)
endif
endif
else
specs_prefix_format = prefix + '/@0@'
endif
build_type_subdir = get_option('build-type-subdir')
lib_dir = prefix / get_option('libdir') / build_type_subdir
include_dir = prefix / get_option('includedir') / build_type_subdir
newlib_iconv_dir = get_option('newlib-iconv-dir')
if newlib_iconv_dir == ''
newlib_iconv_dir = join_paths(lib_dir, 'locale')
endif
newlib_iconv_runtime_dir = get_option('newlib-iconv-runtime-dir')
if newlib_iconv_runtime_dir == ''
newlib_iconv_runtime_dir = newlib_iconv_dir
endif
specs_dir_option = get_option('specsdir')
if build_type_subdir != ''
specs_dir = ''
specs_install = false
elif specs_dir_option == ''
specs_dir = cc_install_dir
specs_install = specs_dir != ''
elif specs_dir_option == 'none'
specs_dir = ''
specs_install = false
else
specs_dir = join_paths(prefix, specs_dir_option)
specs_install = true
endif
# Let targets add more support libraries
additional_libs_list = meson.get_cross_property('additional_libs', [])
compiler_id = cc.get_id()
if compiler_id == 'ccomp'
# When passing the specs file to CompCert, the libcompcert needs to be included there as well
additional_libs_list += '-lcompcert'
endif
additional_libs = ' '.join(additional_libs_list)
if compiler_id == 'gcc' and target_machine.cpu_family() == 'msp430'
# Extract -mhwmult-selection-snippet from GCC.
dumped_specs = run_command(cc.cmd_array() + '-dumpspecs').stdout()
hwmult_start = dumped_specs.split('%{mhwmult=auto')[1]
hwmult_snippet = '%{mhwmult=auto' + hwmult_start.split('-lc')[0]
additional_libs += hwmult_snippet
endif
specs_extra = ''
specs_extra_list = meson.get_cross_property('specs_extra', [])
if specs_extra_list != []
specs_extra = '\n' + '\n'.join(specs_extra_list)
endif
specs_printf = ''
if tinystdio and printf_aliases
specs_printf=('%{DPICOLIBC_DOUBLE_PRINTF_SCANF:--defsym=vfprintf=' + __d_vfprintf_symbol + '}' +
' %{DPICOLIBC_DOUBLE_PRINTF_SCANF:--defsym=vfscanf=' + __d_vfscanf_symbol + '}' +
' %{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfprintf=' + __f_vfprintf_symbol + '}' +
' %{DPICOLIBC_FLOAT_PRINTF_SCANF:--defsym=vfscanf=' + __f_vfscanf_symbol + '}' +
' %{DPICOLIBC_LONG_LONG_PRINTF_SCANF:--defsym=vfprintf=' + __l_vfprintf_symbol + '}' +
' %{DPICOLIBC_LONG_LONG_PRINTF_SCANF:--defsym=vfscanf=' + __l_vfscanf_symbol + '}' +
' %{DPICOLIBC_INTEGER_PRINTF_SCANF:--defsym=vfprintf=' + __i_vfprintf_symbol + '}' +
' %{DPICOLIBC_INTEGER_PRINTF_SCANF:--defsym=vfscanf=' + __i_vfscanf_symbol + '}' +
' %{DPICOLIBC_MINIMAL_PRINTF_SCANF:--defsym=vfprintf=' + __m_vfprintf_symbol + '}' +
' %{DPICOLIBC_MINIMAL_PRINTF_SCANF:--defsym=vfscanf=' + __m_vfscanf_symbol + '}')
endif
crt0_expr = '%{-crt0=*:crt0-%*%O%s; :crt0%O%s}'
if system_libc
specs_isystem = ''
specs_libpath = ''
specs_startfile = crt0_expr
else
#
# Construct path values for specs file
#
# Each of these needs to handle --picolibc-prefix and
# --picolibc-buildtype options, system-root vs absolute paths and
# multilib stuff. That makes this all unreasonably complicated.
#
# Each option is computed in three parts, the 'prefix' value
# (corresponding to --picolibc-prefix), the 'buildtype' value
# (corresponding to --picolibc-buildtype) and the 'gen' value (for
# when neither of these options is specifed).
#
# Because 'getenv' appends a space afterwards in GCC spec files, the
# entire final path elements must be specified inside the parens;
# e.g. %:getenv(FOO a/b/c) instead of %:getenv(FOO)/a/b/c. That means
# we use the specs_prefix_format value computed above to build paths
# instead of simple concatenation
#
#
# How to format each of the three option-selected
# values
#
picolibc_prefix_format = '-picolibc-prefix=*:@0@'
picolibc_buildtype_format = '-picolibc-buildtype=*:@0@'
gen_format = '@0@'
#
# How to glue the three options together
#
specs_option_format = '%{@0@; @1@; :@2@}'
#
# Build the -isystem value
#
prefix_include_dir = '%*/@0@/'.format(get_option('includedir'))
isystem_prefix = picolibc_prefix_format.format(prefix_include_dir)
buildtype_include_dir = specs_prefix_format.format(get_option('includedir') / '%*')
isystem_buildtype = picolibc_buildtype_format.format(buildtype_include_dir)
gen_include_dir = specs_prefix_format.format(get_option('includedir'))
isystem_gen = gen_format.format(gen_include_dir)
specs_isystem = '-isystem ' + specs_option_format.format(isystem_prefix, isystem_buildtype, isystem_gen)
#
# Build the non-multilib -L value
#
prefix_lib_dir = '%*/@0@'.format(get_option('libdir'))
lib_prefix = picolibc_prefix_format.format(prefix_lib_dir)
buildtype_lib_dir = specs_prefix_format.format(get_option('libdir') / '%*')
lib_buildtype = picolibc_buildtype_format.format(buildtype_lib_dir)
gen_lib_dir = specs_prefix_format.format(get_option('libdir'))
lib_gen = gen_format.format(gen_lib_dir)
specs_libpath = '-L' + specs_option_format.format(lib_prefix, lib_buildtype, lib_gen)
#
# Build the non-multilib *startfile options
#
prefix_crt0_path = '%*/@0@'.format(get_option('libdir')) / crt0_expr
crt0_prefix = picolibc_prefix_format.format(prefix_crt0_path)
buildtype_crt0_path = specs_prefix_format.format(get_option('libdir') / '%*' / crt0_expr)
crt0_buildtype = picolibc_buildtype_format.format(buildtype_crt0_path)
gen_crt0_path = specs_prefix_format.format(get_option('libdir') / crt0_expr)
crt0_gen = gen_format.format(gen_crt0_path)
#
# Now build multilib versions of the -L and *startfile values
#
if enable_multilib
#
# Build the multilib -L value
#
prefix_multilib_dir = '%*/@0@'.format(get_option('libdir') / '%M')
multilib_prefix = picolibc_prefix_format.format(prefix_multilib_dir)
buildtype_multilib_dir = specs_prefix_format.format(get_option('libdir') / '%*/%M')
multilib_buildtype = picolibc_buildtype_format.format(buildtype_multilib_dir)
gen_multilib_dir = specs_prefix_format.format(get_option('libdir') / '%M')
multilib_gen = gen_format.format(gen_multilib_dir)
specs_multilibpath = '-L' + specs_option_format.format(multilib_prefix, multilib_buildtype, multilib_gen)
#
# Prepend the multilib -L option to the non-multilib option
#
specs_libpath = specs_multilibpath + ' ' + specs_libpath
#
# Build the multilib *startfile options
#
prefix_multilib_crt0_path = '%*/@0@'.format(get_option('libdir')) / '%M' / crt0_expr
crt0_prefix = picolibc_prefix_format.format(prefix_multilib_crt0_path)
buildtype_multilib_crt0_path = specs_prefix_format.format(get_option('libdir') / '%*/%M' / crt0_expr)
crt0_buildtype = picolibc_buildtype_format.format(buildtype_multilib_crt0_path)
gen_multilib_crt0_path = specs_prefix_format.format(get_option('libdir') / '%M' / crt0_expr)
crt0_gen = gen_format.format(gen_multilib_crt0_path)
endif
#
# Construct the *startfile value from the options computed
# above. As there's only one value, it's either the
# multilib path or the non-multilib path
#
specs_startfile = specs_option_format.format(crt0_prefix, crt0_buildtype, crt0_gen)
endif
specs_data = configuration_data()
specs_data.set('SPECS_ISYSTEM', specs_isystem)
specs_data.set('SPECS_LIBPATH', specs_libpath)
specs_data.set('SPECS_STARTFILE', specs_startfile)
specs_data.set('TLSMODEL', tls_model_spec)
specs_data.set('LINK_SPEC', meson.get_cross_property('link_spec', ''))
specs_data.set('CC1_SPEC', meson.get_cross_property('cc1_spec', ''))
specs_data.set('CC1PLUS_SPEC', meson.get_cross_property('cc1plus_spec', ''))
specs_data.set('ADDITIONAL_LIBS', additional_libs)
specs_data.set('SPECS_EXTRA', specs_extra)
specs_data.set('SPECS_PRINTF', specs_printf)
# Create C and C++ specific specs data,
# that includes setting the correct linker script
# and adding the C++ startup/shutdown files
specs_c_data = specs_data
specs_c_data.set('PICOLIBC_LD', 'picolibc.ld')
specs_c_data.set('CRTBEGIN', '')
specs_c_data.set('CRTEND', '')
specs_cpp_data = specs_data
specs_cpp_data.set('PICOLIBC_LD', 'picolibcpp.ld')
specs_cpp_data.set('CRTBEGIN', 'crtbegin%O%s')
specs_cpp_data.set('CRTEND', 'crtend%O%s')
picolibc_specs = configure_file(input: 'picolibc.specs.in',
output: 'picolibc.specs',
configuration: specs_c_data,
install_dir: specs_dir,
install: specs_install)
picolibc_specs_name = 'picolibc.specs'
picolibcpp_specs = configure_file(input: 'picolibc.specs.in',
output: 'picolibcpp.specs',
configuration: specs_cpp_data,
install_dir: specs_dir,
install: specs_install)
# Not all compilers necessarily support all warnings; only use these which are:
c_warnings = [
'-Werror=implicit-function-declaration',
'-Werror=vla',
'-Warray-bounds',
'-Wold-style-definition',
'-Werror=double-promotion',
]
if get_option('analyzer')
c_warnings += [
'-fanalyzer',
]
endif
disabled_warnings = [
'-Wno-missing-braces',
'-Wno-implicit-int',
'-Wno-return-type',
'-Wno-unused-command-line-argument',
]
c_flags = cc.get_supported_arguments(c_warnings, disabled_warnings)
c_args += c_flags
native_c_args += c_flags
# Make sure _LIBC is not defined when building tests
test_c_args = c_args
c_args += ['-D_LIBC', '-U_FORTIFY_SOURCE']
# Select a fortify source option
fortify_source = get_option('fortify-source')
if fortify_source == 'none'
test_c_args += '-U_FORTIFY_SOURCE'
else
test_c_args += '-D_FORTIFY_SOURCE=' + fortify_source
endif
# CompCert does not support bitfields in packed structs, so avoid using this optimization
bitfields_in_packed_structs_code = '''
struct test { int part: 24; } __attribute__((packed));
unsigned int foobar (const struct test *p) { return p->part; }
'''
have_bitfields_in_packed_structs = cc.compiles(bitfields_in_packed_structs_code, name : 'packed structs may contain bitfields', args: core_c_args)
# CompCert does not have __builtin_mul_overflow
builtin_mul_overflow_code = '''
#include <stddef.h>
int overflows (size_t a, size_t b) { size_t x; return __builtin_mul_overflow(a, b, &x); }
volatile size_t aa = 42;
int main (void) { return overflows(aa, aa); }
'''
have_builtin_mul_overflow = cc.links(builtin_mul_overflow_code, name : 'has __builtin_mul_overflow', args: core_c_args)
# CompCert does not have __builtin_add_overflow
builtin_add_overflow_code = '''
#include <stddef.h>
int overflows (size_t a, size_t b) { size_t x; return __builtin_add_overflow(a, b, &x); }
volatile size_t aa = 42;
int main (void) { return overflows(aa, aa); }
'''
have_builtin_add_overflow = cc.links(builtin_add_overflow_code, name : 'has __builtin_add_overflow', args: core_c_args)
# CompCert does not support _Complex
complex_code = '''
float _Complex test(float _Complex z) { return z; }
'''
have_complex = cc.compiles(complex_code, name : 'supports _Complex', args: core_c_args)
builtin_complex_code = '''
#include <stddef.h>
double _Complex test(double r, double i) { return __builtin_complex(r, i); }
'''
have_builtin_complex = have_complex and cc.compiles(builtin_complex_code, name : 'supports __builtin_complex', args: core_c_args)
# CompCert does not have __builtin_expect
builtin_expect_code = '''
volatile int a = 42;
int main (void) {
return __builtin_expect(a, 1);
}
'''
have_builtin_expect = cc.links(builtin_expect_code, name : 'has __builtin_expect', args: core_c_args)
werror_c_args = core_c_args + cc.get_supported_arguments('-Werror')
# CompCert uses the GCC preprocessor, which causes to
# > #if __has_attribute(__alloc_size__)
# produce a wrong result. So test if the compiler has that attribute
alloc_size_code = '''
void *foobar(int) __attribute__((__alloc_size__(1)));
void *foobar2(int, int) __attribute__((__alloc_size__(1, 2)));
'''
have_alloc_size = cc.compiles(alloc_size_code, name : 'attribute __alloc_size__', args : werror_c_args)
# attributes constructor/destructor are a GNU extension - if the compiler doesn't have them, don't test them.
attr_ctor_dtor_code = '''
void __attribute__((constructor(101))) ctor (void) {}
void __attribute__((destructor(101))) dtor (void) {}
'''
have_attr_ctor_dtor = cc.compiles(attr_ctor_dtor_code, name : 'attributes constructor/destructor', args : werror_c_args)
if enable_multilib
used_libs = []
# Ask the compiler for the set of available multilib configurations,
# set up the build system to compile for all desired ones
target_list = run_command(cc.cmd_array() + get_option('c_args') + ['--print-multi-lib'], check : true).stdout().strip().split('\n')
has_mcmodel = false
foreach target : target_list
if target.contains('mcmodel=')
has_mcmodel = true
endif
endforeach
foreach target : target_list
message('target ' + target)
tmp = target.split(';')
matches_exclude = false
foreach exclude : multilib_exclude
if tmp[0].contains(exclude)
matches_exclude = true
message('skipping target ' + tmp[0])
break
endif
endforeach
if matches_exclude
continue
endif
flags = []
# Let the user specify a subset of the possible multilib
# configurations to build for
if multilib_list == [] or tmp[0] in multilib_list
used_libs += tmp[0]
if tmp.length() > 1
foreach flag : tmp[1].strip('@').split('@')
if flag != ''
if host_cpu_family == 'nios2'
# Hacks for NIOS II to get rid of -fsingle-precision-constant
# mode (which breaks libm). We don't need fph2 as that
# doesn't set the single precision constant flag
if flag == 'mcustom-fpu-cfg=60-1'
flags += ['-mcustom-fmuls=252', '-mcustom-fadds=253',
'-mcustom-fsubs=254']
elif flag == 'mcustom-fpu-cfg=60-2'
flags += ['-mcustom-fmuls=252', '-mcustom-fadds=253',
'-mcustom-fsubs=254', '-mcustom-fdivs=255']
elif flag == 'mcustom-fpu-cfg=72-3'
flags += ['-mcustom-floatus=243', '-mcustom-fixsi=244',
'-mcustom-floatis=245','-mcustom-fcmpgts=246',
'-mcustom-fcmples=249', '-mcustom-fcmpeqs=250',
'-mcustom-fcmpnes=251', '-mcustom-fmuls=252',
'-mcustom-fadds=253', '-mcustom-fsubs=254',
'-mcustom-fdivs=255']
else
flags += '-' + flag
endif
else
flags += '-' + flag
endif
endif
endforeach
if tmp[0] == '.'
name = ''
else
name = tmp[0].underscorify()
endif
else
name = ''
endif
targets += name
# rv64 needs to use a non-default mcmodel so that variables can
# live in a broader range of memory addresses
if not has_mcmodel and name.startswith('rv64')
flags += [ '-mcmodel=medany' ]
endif
# Add any extra flags for this target from the cross file
flags += meson.get_cross_property('c_args_' + name, [])
value = [tmp[0], flags]
set_variable('target_' + name, value)
endif
endforeach
# Make sure all requested multilib configurations
# are actually available
if multilib_list != []
foreach lib : multilib_list
if lib not in used_libs
error('Unavailable multilib: ' + lib)
endif
endforeach
endif
else
targets = ['']
target_ = ['.', []]
endif
foreach target : ['default-target'] + targets
message('generate linker script target ' + target)
custom_mem_config = meson.get_cross_property('custom_mem_config_' + target, '')
if target == 'default-target' or custom_mem_config != ''
picolibc_linker_type_data = configuration_data()
# We need to use different alignment flags for .tdata/.tbss for ld.bfd
# (ALIGN_WITH_INPUT, which is not supported by ld.lld) and ld.lld
# (ALIGN(__tls_align), which is rejected as non-constant by ld.bfd), so we use
# the {BFD,LLD}_{START,END} templates to comment out the incompatible flag.
if cc.get_linker_id() == 'ld.lld'
picolibc_linker_type_data.set('BFD_START', '/* For ld.bfd: ')
picolibc_linker_type_data.set('BFD_END', '*/')
picolibc_linker_type_data.set('LLD_START', '')
picolibc_linker_type_data.set('LLD_END', '')
if host_cpu_family == 'riscv'
# ld.lld before version 15 did not support linker relaxations, disable
# them if we are using an older version.
# There is no `cc.get_linker_version()` function, so we detect ld.lld
# version 15 by checking for a newly added linker flag.
if not cc.has_link_argument('--package-metadata=1')
message('Linking for RISCV with ld.lld < 15, forcing -mno-relax')
c_args += ['-mno-relax']
endif
endif
else
picolibc_linker_type_data.set('BFD_START', '')
picolibc_linker_type_data.set('BFD_END', '')
picolibc_linker_type_data.set('LLD_START', '/* For ld.lld: ')
picolibc_linker_type_data.set('LLD_END', '*/')
endif
init_memory_template = '''
@0@ (rx!w) :
ORIGIN = DEFINED(__@0@) ? __@0@ : @1@,