xref: /dflybsd-src/contrib/gcc-4.7/libgcc/mkmap-flat.awk (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino# Generate a flat list of symbols to export.
2*e4b17023SJohn Marino#	Copyright (C) 2007, 2008, 2009, 2011  Free Software Foundation, Inc.
3*e4b17023SJohn Marino#	Contributed by Richard Henderson <rth@cygnus.com>
4*e4b17023SJohn Marino#
5*e4b17023SJohn Marino# This file is part of GCC.
6*e4b17023SJohn Marino#
7*e4b17023SJohn Marino# GCC is free software; you can redistribute it and/or modify it under
8*e4b17023SJohn Marino# the terms of the GNU General Public License as published by the Free
9*e4b17023SJohn Marino# Software Foundation; either version 3, or (at your option) any later
10*e4b17023SJohn Marino# version.
11*e4b17023SJohn Marino#
12*e4b17023SJohn Marino# GCC is distributed in the hope that it will be useful, but WITHOUT
13*e4b17023SJohn Marino# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14*e4b17023SJohn Marino# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15*e4b17023SJohn Marino# License for more details.
16*e4b17023SJohn Marino#
17*e4b17023SJohn Marino# You should have received a copy of the GNU General Public License
18*e4b17023SJohn Marino# along with GCC; see the file COPYING3.  If not see
19*e4b17023SJohn Marino# <http://www.gnu.org/licenses/>.
20*e4b17023SJohn Marino
21*e4b17023SJohn Marino# Options:
22*e4b17023SJohn Marino#   "-v leading_underscore=1" : Symbols in map need leading underscore.
23*e4b17023SJohn Marino#   "-v osf_export=1"	      : Create -input file for Tru64 UNIX linker
24*e4b17023SJohn Marino#				instead of map file.
25*e4b17023SJohn Marino#   "-v pe_dll=1"             : Create .DEF file for Windows PECOFF
26*e4b17023SJohn Marino#                               DLL link instead of map file.
27*e4b17023SJohn Marino
28*e4b17023SJohn MarinoBEGIN {
29*e4b17023SJohn Marino  state = "nm";
30*e4b17023SJohn Marino  excluding = 0;
31*e4b17023SJohn Marino  if (leading_underscore)
32*e4b17023SJohn Marino    prefix = "_";
33*e4b17023SJohn Marino  else
34*e4b17023SJohn Marino    prefix = "";
35*e4b17023SJohn Marino}
36*e4b17023SJohn Marino
37*e4b17023SJohn Marino# Remove comment and blank lines.
38*e4b17023SJohn Marino/^ *#/ || /^ *$/ {
39*e4b17023SJohn Marino  next;
40*e4b17023SJohn Marino}
41*e4b17023SJohn Marino
42*e4b17023SJohn Marino# We begin with nm input.  Collect the set of symbols that are present
43*e4b17023SJohn Marino# so that we can elide undefined symbols.
44*e4b17023SJohn Marino
45*e4b17023SJohn Marinostate == "nm" && /^%%/ {
46*e4b17023SJohn Marino  state = "ver";
47*e4b17023SJohn Marino  next;
48*e4b17023SJohn Marino}
49*e4b17023SJohn Marino
50*e4b17023SJohn Marinostate == "nm" && ($1 == "U" || $2 == "U") {
51*e4b17023SJohn Marino  next;
52*e4b17023SJohn Marino}
53*e4b17023SJohn Marino
54*e4b17023SJohn Marinostate == "nm" && NF == 3 {
55*e4b17023SJohn Marino  def[$3] = 1;
56*e4b17023SJohn Marino  next;
57*e4b17023SJohn Marino}
58*e4b17023SJohn Marino
59*e4b17023SJohn Marinostate == "nm" {
60*e4b17023SJohn Marino  next;
61*e4b17023SJohn Marino}
62*e4b17023SJohn Marino
63*e4b17023SJohn Marino# Now we process a simplified variant of the Solaris symbol version
64*e4b17023SJohn Marino# script.  We have one symbol per line, no semicolons, simple markers
65*e4b17023SJohn Marino# for beginning and ending each section, and %inherit markers for
66*e4b17023SJohn Marino# describing version inheritance.  A symbol may appear in more than
67*e4b17023SJohn Marino# one symbol version, and the last seen takes effect.
68*e4b17023SJohn Marino# The magic version name '%exclude' causes all the symbols given that
69*e4b17023SJohn Marino# version to be dropped from the output (unless a later version overrides).
70*e4b17023SJohn Marino
71*e4b17023SJohn MarinoNF == 3 && $1 == "%inherit" {
72*e4b17023SJohn Marino  next;
73*e4b17023SJohn Marino}
74*e4b17023SJohn Marino
75*e4b17023SJohn MarinoNF == 2 && $2 == "{" {
76*e4b17023SJohn Marino  if ($1 == "%exclude")
77*e4b17023SJohn Marino    excluding = 1;
78*e4b17023SJohn Marino  next;
79*e4b17023SJohn Marino}
80*e4b17023SJohn Marino
81*e4b17023SJohn Marino$1 == "}" {
82*e4b17023SJohn Marino  excluding = 0;
83*e4b17023SJohn Marino  next;
84*e4b17023SJohn Marino}
85*e4b17023SJohn Marino
86*e4b17023SJohn Marino{
87*e4b17023SJohn Marino  sym = prefix $1;
88*e4b17023SJohn Marino  if (excluding)
89*e4b17023SJohn Marino    delete export[sym];
90*e4b17023SJohn Marino  else
91*e4b17023SJohn Marino    export[sym] = 1;
92*e4b17023SJohn Marino  next;
93*e4b17023SJohn Marino}
94*e4b17023SJohn Marino
95*e4b17023SJohn MarinoEND {
96*e4b17023SJohn Marino
97*e4b17023SJohn Marino  if (pe_dll) {
98*e4b17023SJohn Marino    print "LIBRARY " pe_dll;
99*e4b17023SJohn Marino    print "EXPORTS";
100*e4b17023SJohn Marino  }
101*e4b17023SJohn Marino
102*e4b17023SJohn Marino  for (sym in export)
103*e4b17023SJohn Marino    if (def[sym] || (pe_dll && def["_" sym])) {
104*e4b17023SJohn Marino      if (!osf_export)
105*e4b17023SJohn Marino	print sym;
106*e4b17023SJohn Marino      else
107*e4b17023SJohn Marino	print "-exported_symbol " sym;
108*e4b17023SJohn Marino    }
109*e4b17023SJohn Marino}
110