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