// stringpool.h -- a string pool for gold -*- C++ -*-
+// Copyright 2006, 2007 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@google.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
#include <string>
#include <list>
// string pointer so that repeated runs of the linker will generate
// precisely the same output.
-// When you add a string to a Stringpool, Stringpool will make a copy
-// of it. Thus there is no need to keep a copy elsewhere.
+// When you add a string to a Stringpool, Stringpool will optionally
+// make a copy of it. Thus there is no requirement to keep a copy
+// elsewhere.
// A Stringpool can be turned into a string table, a sequential series
// of null terminated strings. The first string may optionally be a
// is never a valid key value.
typedef size_t Key;
- // Create a Stringpool. ZERO_NULL is true if we should reserve
- // offset 0 to hold the empty string when converting the stringpool
- // to a string table. ZERO_NULL should be true if you want a proper
- // ELF SHT_STRTAB section.
- Stringpool_template(bool zero_null = true);
+ // Create a Stringpool.
+ Stringpool_template();
~Stringpool_template();
- // Add the string S to the pool. This returns a canonical permanent
- // pointer to the string in the pool. If PKEY is not NULL, this
- // sets *PKEY to the key for the string.
- const Stringpool_char*
- add(const Stringpool_char* s, Key* pkey);
+ // Clear all the data from the stringpool.
+ void
+ clear();
- // Add the string S to the pool.
+ // Indicate that we should not reserve offset 0 to hold the empty
+ // string when converting the stringpool to a string table. This
+ // should not be called for a proper ELF SHT_STRTAB section.
+ void
+ set_no_zero_null()
+ { this->zero_null_ = false; }
+
+ // Add the string S to the pool. This returns a canonical permanent
+ // pointer to the string in the pool. If COPY is true, the string
+ // is copied into permanent storage. If PKEY is not NULL, this sets
+ // *PKEY to the key for the string.
const Stringpool_char*
- add(const std::basic_string<Stringpool_char>& s, Key* pkey)
- { return this->add(s.c_str(), pkey); }
+ add(const Stringpool_char* s, bool copy, Key* pkey);
// Add the prefix of length LEN of string S to the pool.
const Stringpool_char*
- add(const Stringpool_char* s, size_t len, Key* pkey);
+ add_prefix(const Stringpool_char* s, size_t len, Key* pkey);
// If the string S is present in the pool, return the canonical
// string pointer. Otherwise, return NULL. If PKEY is not NULL,
void
write(Output_file*, off_t offset);
+ // Write the string table into the specified buffer, of the
+ // specified size. buffer_size should be at least
+ // get_strtab_size().
+ void
+ write_to_buffer(unsigned char* buffer, size_t buffer_size);
+
+ // Dump statistical information to stderr.
+ void
+ print_stats(const char*) const;
+
private:
Stringpool_template(const Stringpool_template&);
Stringpool_template& operator=(const Stringpool_template&);
off_t strtab_size_;
// Next Stringdata index.
unsigned int next_index_;
+ // Next key value for a string we don't copy.
+ int next_uncopied_key_;
// Whether to reserve offset 0 to hold the null string.
bool zero_null_;
};