@@ -133,7 +133,11 @@ def clean():
133
133
def toolchain (target ):
134
134
# basic CFLAGS setup
135
135
c_flags = f"-I{ ROOT } /include"
136
- if "-O" not in target .cflags : c_flags += " -Os"
136
+ if "-O" not in target .cflags :
137
+ if args .size_tfm and target .compiler in { "clang" , "armclang" }:
138
+ c_flags += " -Oz"
139
+ else :
140
+ c_flags += " -Os"
137
141
if "-std" not in target .cflags : c_flags += " -std=c99"
138
142
if args .no_warnings :
139
143
c_flags += " -Wno-everything"
@@ -375,18 +379,26 @@ def disassemble(target):
375
379
objdump = toolchain (target )["OBJDUMP" ]
376
380
objfiles = ["library/libmbedcrypto.a" , "library/libmbedtls.a" , "library/libmbedx509.a" ] + args .build_targets
377
381
objfiles = [f"{ ROOT } /{ f } " for f in objfiles if os .path .exists (f"{ ROOT } /{ f } " )]
378
- output , _ = subrun ([objdump ] + objfiles + [f"--disassemble={ args .disassemble } " , "--visualize-jumps=extended-color" ], silent = True )
379
- # extract the relevant bit of output
380
- found = False
381
- diss = []
382
- for l in output .splitlines ():
383
- if l .strip ().endswith (f"{ args .disassemble } >:" ):
384
- found = True
385
- if found and re .search (r"[\w_]+.o:\s+file format" , l ): break
386
- if found and l .strip ().startswith ("Disassembly of section" ): break
387
- if found : diss .append (l )
388
- while diss [- 1 ] == "" : diss = diss [:- 1 ]
389
- return "\n " .join (diss )
382
+ if args .disassemble == True :
383
+ disarg = "--disassemble"
384
+ else :
385
+ disarg = f"--disassemble={ args .disassemble } "
386
+ output , _ = subrun ([objdump ] + objfiles + [disarg , "--visualize-jumps=extended-color" ], silent = True )
387
+ if args .disassemble == True :
388
+ # return complete output
389
+ return output
390
+ else :
391
+ # extract the relevant bit of output
392
+ found = False
393
+ diss = []
394
+ for l in output .splitlines ():
395
+ if l .strip ().endswith (f"{ args .disassemble } >:" ):
396
+ found = True
397
+ if found and re .search (r"[\w_]+.o:\s+file format" , l ): break
398
+ if found and l .strip ().startswith ("Disassembly of section" ): break
399
+ if found : diss .append (l )
400
+ while len (diss ) > 0 and diss [- 1 ] == "" : diss = diss [:- 1 ]
401
+ return "\n " .join (diss )
390
402
391
403
392
404
def build (target , tests ):
@@ -437,7 +449,12 @@ def size(target):
437
449
size_target = "library/libmbedcrypto.a"
438
450
log (f'{ t ["SIZE" ]} { size_target } ' )
439
451
size = subrun ([t ["SIZE" ], size_target ], silent = True )[0 ]
440
- log (size )
452
+ lines = size .splitlines ()
453
+ # sort modules by text+data size
454
+ lines = lines [:1 ] + sorted (lines [1 :], key = lambda l :int (l .split ()[0 ]) + int (l .split ()[1 ]))
455
+ for l in lines :
456
+ # skip modules with zero size
457
+ if not re .search (r"^\s*0\s+0\s+0\s+0\s+0\s" , l ): log (l )
441
458
size_data = [x .split ()[0 :3 ] for x in size .splitlines ()[1 :]]
442
459
text_sum = sum (int (x [0 ]) for x in size_data )
443
460
data_sum = sum (int (x [1 ]) for x in size_data )
@@ -507,13 +524,17 @@ mtest base64 armv6-thumb1 aarch64 x86_64
507
524
Run alignment test suite on key targets:
508
525
mtest -k alignment
509
526
510
- Report library size, as built with TF-M configuration for armv8 thumb2:
527
+ Report library size, as built by armclang -Oz with TF-M configuration for armv8 thumb2:
511
528
mtest -S
529
+ mtest -S clang # as above, but use clang instead of the default armclang
512
530
513
531
Build aes.o multiple times, with every combination of the given options:
514
532
mtest aes.o MBEDTLS_AES_SETKEY_ENC_ALT,MBEDTLS_AES_DECRYPT_ALT,MBEDTLS_AES_ROM_TABLES,MBEDTLS_AES_ENCRYPT_ALT,MBEDTLS_AES_SETKEY_DEC_ALT,MBEDTLS_AES_FEWER_TABLES,MBEDTLS_PADLOCK_C
515
533
516
- Disassemble mbedtls_xor for arm, built with clang -Os
534
+ Disassemble cmac.o
535
+ mtest cmac.o -d
536
+
537
+ Disassemble mbedtls_xor, built with clang -Os for arm
517
538
mtest -d mbedtls_xor -Os clang arm
518
539
'''
519
540
@@ -536,9 +557,9 @@ Build targets: build the library by default, or files (e.g. aes.o), programs (e.
536
557
parser .add_argument ('-A' , '--asan' , action = "store_true" , default = False , help = "make an ASAN build" )
537
558
parser .add_argument ('-W' , '--no-warnings' , action = "store_true" , default = False , help = "disable warnings" )
538
559
parser .add_argument ('-C' , '--no-clean' , action = "store_true" , default = False , help = "don't run make clean (if building for a single target)" )
539
- parser .add_argument ('-d' , '--disassemble' , metavar = 'function' , action = "store" , default = None , help = "disassemble specified function" )
560
+ parser .add_argument ('-d' , '--disassemble' , metavar = 'function' , action = "store" , nargs = '?' , const = True , default = None , help = "disassemble specified function (or everything if no function specified) " )
540
561
parser .add_argument ('-s' , '--size' , action = "store_true" , default = False , help = "display size of library / given build target" )
541
- parser .add_argument ('-S' , '--size-tfm' , action = "store_true" , default = False , help = f"as --size, but use the TF-M config file and build with { SIZE_TFM_COMPILER } -Os for Cortex-M33" )
562
+ parser .add_argument ('-S' , '--size-tfm' , action = "store_true" , default = False , help = f"as --size, but use the TF-M config file and build with { SIZE_TFM_COMPILER } -Oz for Cortex-M33" )
542
563
parser .add_argument ('-j' , '--jobs' , nargs = '?' , const = - 1 , metavar = 'N' , action = "store" , type = int , help = "enable parallel builds, like 'make -j'. Alternatively, set the MAKEFLAGS environment variable" )
543
564
parser .add_argument ('rest' , metavar = 'args' , nargs = '*' , help = REST_HELP )
544
565
# handle -MBEDTLS_OPTION style args manually because they confuse argparse w.r.t. -M for --memsan
@@ -585,18 +606,18 @@ Build targets: build the library by default, or files (e.g. aes.o), programs (e.
585
606
if args .size_tfm :
586
607
config .append ("tfm_mbedcrypto_config_profile_medium.h" )
587
608
config .append ("crypto_config_profile_medium.h" )
588
- for a in args .rest :
609
+ for a in list ( args .rest ) :
589
610
if a .endswith (".h" ) and os .path .exists (a ):
590
611
# arbitrary .h file
591
612
config .append (a )
592
613
args .rest .remove (a )
593
- break
614
+ continue
594
615
x = a .split ("/" )[- 1 ] if "configs/" in a else a
595
616
if x in supported_configs or f"{ x } .h" in supported_configs :
596
617
# file in configs directory, or a known argument to set_config.py
597
618
config .append (f"{ x } .h" if f"{ x } .h" in supported_configs else x )
598
619
args .rest .remove (a )
599
- break
620
+ continue
600
621
601
622
# filter out non-config options, and non-flags
602
623
args .rest = [x for x in args .rest if not x .startswith ("-" ) and not x .startswith ("MBEDTLS_" ) and not x .startswith ("PSA_WANT_" )]
0 commit comments