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