Remove ALL_OBJFILE_COMPUNITS
[deliverable/binutils-gdb.git] / gold / gc.cc
CommitLineData
6d03d481
ST
1// gc.cc -- garbage collection of unused sections
2
82704155 3// Copyright (C) 2009-2019 Free Software Foundation, Inc.
6d03d481
ST
4// Written by Sriraman Tallam <tmsriram@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21// MA 02110-1301, USA.
22
23
24#include "gold.h"
25#include "object.h"
26#include "gc.h"
27#include "symtab.h"
28
29namespace gold
30{
31
32// Garbage collection uses a worklist style algorithm to determine the
33// transitive closure of all referenced sections.
34void
35Garbage_collection::do_transitive_closure()
36{
37 while (!this->worklist().empty())
38 {
39 // Add elements from the work list to the referenced list
40 // one by one.
4277535c
RÁE
41 Section_id entry = this->worklist().back();
42 this->worklist().pop_back();
5368dcf2
RÁE
43 if (!this->referenced_list().insert(entry).second)
44 continue;
6d03d481
ST
45 Garbage_collection::Section_ref::iterator find_it =
46 this->section_reloc_map().find(entry);
47 if (find_it == this->section_reloc_map().end())
48 continue;
9dbb4b02 49 const Garbage_collection::Sections_reachable &v = find_it->second;
6d03d481 50 // Scan the vector of references for each work_list entry.
9dbb4b02
RÁE
51 for (Garbage_collection::Sections_reachable::const_iterator it_v =
52 v.begin();
6d03d481
ST
53 it_v != v.end();
54 ++it_v)
55 {
56 // Do not add already processed sections to the work_list.
57 if (this->referenced_list().find(*it_v)
58 == this->referenced_list().end())
59 {
4277535c 60 this->worklist().push_back(*it_v);
6d03d481
ST
61 }
62 }
63 }
64 this->worklist_ready();
65}
66
67} // End namespace gold.
68
This page took 0.449772 seconds and 4 git commands to generate.