1#!/usr/bin/env python 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2017, Linaro Limited 5# 6 7import sys 8import re 9 10def usage(): 11 print "Usage: {0} <section reg exp match> [<skip section>...]".format( \ 12 sys.argv[0]) 13 sys.exit (1) 14 15def main(): 16 if len(sys.argv) < 2 : 17 usage() 18 19 in_shdr = False 20 section_headers = re.compile("Section Headers:") 21 key_to_flags = re.compile("Key to Flags:") 22 match_rule = re.compile(sys.argv[1]) 23 skip_sections = sys.argv[2:] 24 25 for line in sys.stdin: 26 if section_headers.match(line) : 27 in_shdr = True; 28 continue 29 if key_to_flags.match(line) : 30 in_shdr = False; 31 continue 32 33 if not in_shdr : 34 continue 35 36 words = line.split() 37 38 if len(words) < 3 : 39 continue 40 41 if words[0] == "[" : 42 name_offs = 2 43 else : 44 name_offs = 1; 45 46 sect_name = words[name_offs] 47 sect_type = words[name_offs + 1] 48 49 if sect_type != "PROGBITS" : 50 continue 51 52 if not match_rule.match(sect_name) : 53 continue 54 55 if sect_name in skip_sections : 56 continue 57 58 print '\t*({0})'.format(sect_name) 59 60if __name__ == "__main__": 61 main() 62