1bfed486aSAli Bahrami#! /usr/bin/python 2bfed486aSAli Bahrami# 3bfed486aSAli Bahrami# CDDL HEADER START 4bfed486aSAli Bahrami# 5bfed486aSAli Bahrami# The contents of this file are subject to the terms of the 6bfed486aSAli Bahrami# Common Development and Distribution License (the "License"). 7bfed486aSAli Bahrami# You may not use this file except in compliance with the License. 8bfed486aSAli Bahrami# 9bfed486aSAli Bahrami# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10bfed486aSAli Bahrami# or http://www.opensolaris.org/os/licensing. 11bfed486aSAli Bahrami# See the License for the specific language governing permissions 12bfed486aSAli Bahrami# and limitations under the License. 13bfed486aSAli Bahrami# 14bfed486aSAli Bahrami# When distributing Covered Code, include this CDDL HEADER in each 15bfed486aSAli Bahrami# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16bfed486aSAli Bahrami# If applicable, add the following below this CDDL HEADER, with the 17bfed486aSAli Bahrami# fields enclosed by brackets "[]" replaced with your own identifying 18bfed486aSAli Bahrami# information: Portions Copyright [yyyy] [name of copyright owner] 19bfed486aSAli Bahrami# 20bfed486aSAli Bahrami# CDDL HEADER END 21bfed486aSAli Bahrami# 22bfed486aSAli Bahrami 23bfed486aSAli Bahrami# 24*cd3e9333SAli Bahrami# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 25bfed486aSAli Bahrami# 26bfed486aSAli Bahrami 27bfed486aSAli Bahrami# 28bfed486aSAli Bahrami# Check that link-editor mapfiles contain a valid mapfile header block 29bfed486aSAli Bahrami# 30bfed486aSAli Bahrami 31bfed486aSAli BahramiMAPFILE = ''' 32bfed486aSAli BahramiWARNING: STOP NOW. DO NOT MODIFY THIS FILE. 33bfed486aSAli BahramiObject versioning must comply with the rules detailed in 34bfed486aSAli Bahrami 35bfed486aSAli Bahrami usr/src/lib/README.mapfiles 36bfed486aSAli Bahrami 37bfed486aSAli BahramiYou should not be making modifications here until you've read the most current 38bfed486aSAli Bahramicopy of that file. If you need help, contact a gatekeeper for guidance. 39bfed486aSAli Bahrami''' 40bfed486aSAli Bahrami 41*cd3e9333SAli Bahramiimport re, sys, CmtBlk 42bfed486aSAli Bahrami 43bfed486aSAli BahramiMAPFILE = MAPFILE.splitlines()[1:] # Don't include initial \n 44bfed486aSAli Bahrami 45bfed486aSAli Bahramidef mapfilechk(fh, filename=None, verbose=False, output=sys.stderr): 46*cd3e9333SAli Bahrami if filename: 47*cd3e9333SAli Bahrami name = filename 48*cd3e9333SAli Bahrami else: 49*cd3e9333SAli Bahrami name = fh.name 50*cd3e9333SAli Bahrami 51*cd3e9333SAli Bahrami # Verify that the mapfile is using version 2 syntax. Read and discard 52*cd3e9333SAli Bahrami # comment and empty lines until the first non-empty line is seen. 53*cd3e9333SAli Bahrami # This line must be '$mapfile_version 2'. 54*cd3e9333SAli Bahrami CmtRE = re.compile(r'#.*$') 55*cd3e9333SAli Bahrami LeadingWSRE = re.compile(r'^\s+') 56*cd3e9333SAli Bahrami VersionRE = re.compile(r'^\$mapfile_version\s+2\s*$') 57*cd3e9333SAli Bahrami for line in fh: 58*cd3e9333SAli Bahrami line = CmtRE.sub(r'', line) 59*cd3e9333SAli Bahrami line = LeadingWSRE.sub(r'', line) 60*cd3e9333SAli Bahrami if line == '' : 61*cd3e9333SAli Bahrami continue 62*cd3e9333SAli Bahrami 63*cd3e9333SAli Bahrami # First non=empty line must be version declaration 64*cd3e9333SAli Bahrami if not VersionRE.match(line): 65*cd3e9333SAli Bahrami output.write("Warning: mapfile version 2 syntax" 66*cd3e9333SAli Bahrami " expected in file %s\n" % name) 67*cd3e9333SAli Bahrami return 1 68*cd3e9333SAli Bahrami 69*cd3e9333SAli Bahrami # We have verified version 2 syntax. Exit the loop 70*cd3e9333SAli Bahrami break 71*cd3e9333SAli Bahrami 72*cd3e9333SAli Bahrami 73*cd3e9333SAli Bahrami # If the mapfile contains a SYMBOL_VERSION directive, the file 74*cd3e9333SAli Bahrami # must include a copy of the MAPFILE warning comment above. The 75*cd3e9333SAli Bahrami # comment is specific to symbol versioning, so we don't harrass 76*cd3e9333SAli Bahrami # the authors of mapfiles used exclusively for other purposes. 77*cd3e9333SAli Bahrami SymVerRE = re.compile(r'^\s*symbol_version\s+', re.IGNORECASE) 78*cd3e9333SAli Bahrami for line in fh: 79*cd3e9333SAli Bahrami # If we find a SYMBOL_VERSION, then verify that the comment 80*cd3e9333SAli Bahrami # is present. The comment usually precedes the mapfile_version 81*cd3e9333SAli Bahrami # comment and any mapfile directives (including SYMBOL_VERSION), 82*cd3e9333SAli Bahrami # so we need to rewind the file. This is more efficient than it 83*cd3e9333SAli Bahrami # might seem: All of these items are near the top of the file, 84*cd3e9333SAli Bahrami # so not not many lines are read, and file contents are 85*cd3e9333SAli Bahrami # bufferred. 86*cd3e9333SAli Bahrami if SymVerRE.match(line): 87*cd3e9333SAli Bahrami fh.seek(0); 88*cd3e9333SAli Bahrami return CmtBlk.cmtblkchk(fh, 'MAPFILE', MAPFILE, 89*cd3e9333SAli Bahrami filename=filename, verbose=verbose, 90*cd3e9333SAli Bahrami output=output) 91*cd3e9333SAli Bahrami 92*cd3e9333SAli Bahrami # Comment is not required. 93*cd3e9333SAli Bahrami return 0 94