2009-08-05 Chao-ying Fu <fu@mips.com>
[deliverable/binutils-gdb.git] / gold / script-sections.h
index ec708bd50d1792879d5a8e636413ab48f953d679..390c35089678cb301ae3c08f8ead73b84dc2e512 100644 (file)
@@ -1,6 +1,6 @@
 // script-sections.h -- linker script SECTIONS for gold   -*- C++ -*-
 
-// Copyright 2008 Free Software Foundation, Inc.
+// Copyright 2008, 2009 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -26,6 +26,7 @@
 #define GOLD_SCRIPT_SECTIONS_H
 
 #include <cstdio>
+#include <list>
 #include <vector>
 
 namespace gold
@@ -36,12 +37,20 @@ struct Parser_output_section_trailer;
 struct Input_section_spec;
 class Expression;
 class Sections_element;
+class Phdrs_element;
+class Output_data;
 class Output_section_definition;
 class Output_section;
 class Output_segment;
+class Orphan_section_placement;
 
 class Script_sections
 {
+ private:
+  // This is a list, not a vector, because we insert orphan sections
+  // in the middle.
+  typedef std::list<Sections_element*> Sections_elements;
+
  public:
   Script_sections();
 
@@ -64,6 +73,12 @@ class Script_sections
   in_sections_clause() const
   { return this->in_sections_clause_; }
 
+  // Return whether we ever saw a PHDRS clause.  We ignore the PHDRS
+  // clause unless we also saw a SECTIONS clause.
+  bool
+  saw_phdrs_clause() const
+  { return this->saw_sections_clause_ && this->phdrs_elements_ != NULL; }
+
   // Start processing entries for an output section.
   void
   start_output_section(const char* name, size_t namelen,
@@ -98,6 +113,18 @@ class Script_sections
   void
   add_input_section(const Input_section_spec* spec, bool keep);
 
+  // Saw DATA_SEGMENT_ALIGN.
+  void
+  data_segment_align();
+
+  // Saw DATA_SEGMENT_RELRO_END.
+  void
+  data_segment_relro_end();
+
+  // Create any required sections.
+  void
+  create_sections(Layout*);
+
   // Add any symbols we are defining to the symbol table.
   void
   add_symbols_to_table(Symbol_table*);
@@ -134,17 +161,41 @@ class Script_sections
   Output_segment*
   set_section_addresses(Symbol_table*, Layout*);
 
+  // Add a program header definition.
+  void
+  add_phdr(const char* name, size_t namelen, unsigned int type,
+          bool filehdr, bool phdrs, bool is_flags_valid, unsigned int flags,
+          Expression* load_address);
+
   // Return the number of segments we expect to create based on the
   // SECTIONS clause.
   size_t
   expected_segment_count(const Layout*) const;
 
+  // Add the file header and segment header to non-load segments as
+  // specified by the PHDRS clause.
+  void
+  put_headers_in_phdrs(Output_data* file_header, Output_data* segment_headers);
+
+  // Look for an output section by name and return the address, the
+  // load address, the alignment, and the size.  This is used when an
+  // expression refers to an output section which was not actually
+  // created.  This returns true if the section was found, false
+  // otherwise.
+  bool
+  get_output_section_info(const char* name, uint64_t* address,
+                          uint64_t* load_address, uint64_t* addralign,
+                          uint64_t* size) const;
+
   // Print the contents to the FILE.  This is for debugging.
   void
   print(FILE*) const;
 
+  // Used for orphan sections.
+  typedef Sections_elements::iterator Elements_iterator;
+
  private:
-  typedef std::vector<Sections_element*> Sections_elements;
+  typedef std::vector<Phdrs_element*> Phdrs_elements;
 
   // Create segments.
   Output_segment*
@@ -158,6 +209,27 @@ class Script_sections
   static bool
   is_bss_section(const Output_section*);
 
+  // Return the total size of the headers.
+  size_t
+  total_header_size(Layout* layout) const;
+
+  // Return the amount we have to subtract from the LMA to accomodate
+  // headers of the given size.
+  uint64_t
+  header_size_adjustment(uint64_t lma, size_t sizeof_headers) const;
+
+  // Create the segments from a PHDRS clause.
+  Output_segment*
+  create_segments_from_phdrs_clause(Layout* layout);
+
+  // Attach sections to segments from a PHDRS clause.
+  void
+  attach_sections_using_phdrs_clause(Layout*);
+
+  // Set addresses of segments from a PHDRS clause.
+  Output_segment*
+  set_phdrs_clause_addresses(Layout*);
+
   // True if we ever saw a SECTIONS clause.
   bool saw_sections_clause_;
   // True if we are currently processing a SECTIONS clause.
@@ -166,6 +238,17 @@ class Script_sections
   Sections_elements* sections_elements_;
   // The current output section, if there is one.
   Output_section_definition* output_section_;
+  // The list of program headers in the PHDRS clause.
+  Phdrs_elements* phdrs_elements_;
+  // Where to put orphan sections.
+  Orphan_section_placement* orphan_section_placement_;
+  // A pointer to the last Sections_element when we see
+  // DATA_SEGMENT_ALIGN.
+  Sections_elements::iterator data_segment_align_start_;
+  // Whether we have seen DATA_SEGMENT_ALIGN.
+  bool saw_data_segment_align_;
+  // Whether we have seen DATA_SEGMENT_RELRO_END.
+  bool saw_relro_end_;
 };
 
 } // End namespace gold.
This page took 0.024178 seconds and 4 git commands to generate.