summaryrefslogtreecommitdiffstats
path: root/binutils-2.25/gold/gold.cc
diff options
context:
space:
mode:
authorHan Shen <shenhan@google.com>2015-11-18 00:29:47 (GMT)
committerHan Shen <shenhan@google.com>2015-11-20 01:29:00 (GMT)
commit8bfb6b2bf11cfbc445239158ec28d0988f8fa947 (patch)
tree64baf9be2b2d76eb0d3d83ec6acf3d5ddd452b64 /binutils-2.25/gold/gold.cc
parent932d71b859239e834651fdee549dc661cda82fe8 (diff)
downloadtoolchain_binutils-8bfb6b2bf11cfbc445239158ec28d0988f8fa947.zip
toolchain_binutils-8bfb6b2bf11cfbc445239158ec28d0988f8fa947.tar.gz
toolchain_binutils-8bfb6b2bf11cfbc445239158ec28d0988f8fa947.tar.bz2
Create an unified binutils source tree for both Android and ChromiumOS.
About source code - The base version of this binutils is newer than that of aosp/binutils-2.25, it is based on the binutils that is used to build google products and ChromiumOS. And it contains *all* local Android patches as well as all patches that are cherry-picked from upstream for aosp/binutils-2.25 tree (up to Nov. 5 - 932d71b85). You may find the detailed development history for this binutils tree here - https://chromium.googlesource.com/chromiumos/third_party/binutils/+log/unification (This CL is a combination of all the CLs in it. After this CL is submitted the tree will be identical to https://chromium.googlesource.com/chromiumos/third_party/binutils/+log/unification at 2865a3615d80bd5f82d14d7e0484e84dc052596a) About testing - We tested this binutils for both ChromiumOS and Android. For android, we tested building N4, N5X, N6, N7, N9 using new binutils, we also did a full-build of toolchain (by build.py) and built a N5X image; for ChromiumOS - it passed ChromiumOS toolchain release tests on all 4 platforms (x86, x86_64, arm32 and arm64). Change-Id: I2bb2cf579f9458d0a8bc9612331dc7d5043e3d82
Diffstat (limited to 'binutils-2.25/gold/gold.cc')
-rw-r--r--binutils-2.25/gold/gold.cc68
1 files changed, 56 insertions, 12 deletions
diff --git a/binutils-2.25/gold/gold.cc b/binutils-2.25/gold/gold.cc
index ab15980..eccbc58 100644
--- a/binutils-2.25/gold/gold.cc
+++ b/binutils-2.25/gold/gold.cc
@@ -1,6 +1,6 @@
// gold.cc -- main linker functions
-// Copyright (C) 2006-2015 Free Software Foundation, Inc.
+// Copyright (C) 2006-2014 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -552,6 +552,61 @@ queue_middle_tasks(const General_options& options,
plugins->layout_deferred_objects();
}
+ // We have to support the case of not seeing any input objects, and
+ // generate an empty file. Existing builds depend on being able to
+ // pass an empty archive to the linker and get an empty object file
+ // out. In order to do this we need to use a default target.
+ if (input_objects->number_of_input_objects() == 0
+ && layout->incremental_base() == NULL)
+ parameters_force_valid_target();
+
+ // TODO(tmsriram): figure out a more principled way to get the target
+ Target* target = const_cast<Target*>(&parameters->target());
+
+ // Check if we need to disable PIE because of an unsafe data segment size.
+ // Go through each Output section and get the size. At this point, we do not
+ // have the exact size of the data segment but this is a very close estimate.
+ // We are doing this here because disabling PIE later is too late. Further,
+ // if we miss some cases which are on the edge, it will be caught later in
+ // layout.cc where we check with the exact size of the data segment and warn
+ // if it is breached.
+ if (parameters->options().disable_pie_when_unsafe_data_size()
+ && parameters->options().pie() && target->max_pie_data_segment_size())
+ {
+ uint64_t segment_size = 0;
+ for (Layout::Section_list::const_iterator p = layout->section_list().begin();
+ p != layout->section_list().end();
+ ++p)
+ {
+ Output_section *os = *p;
+ if (os->is_section_flag_set(elfcpp::SHF_ALLOC)
+ && os->is_section_flag_set(elfcpp::SHF_WRITE))
+ {
+ segment_size += os->current_data_size();
+ }
+ // Count read-only sections if --rosegment is set.
+ else if (parameters->options().rosegment()
+ && os->is_section_flag_set(elfcpp::SHF_ALLOC)
+ && !os->is_section_flag_set(elfcpp::SHF_EXECINSTR))
+ {
+ segment_size += os->current_data_size();
+ }
+ }
+ // Should we inflate the value of segment_size to account for relaxation?
+ // If we miss disabling PIE here, the check in layout.cc will catch it
+ // perfectly and warn. So, this is fine.
+ if (segment_size >= target->max_pie_data_segment_size())
+ {
+ gold_info(_("The data segment size (%ld > %ld) is likely unsafe and"
+ " PIE has been disabled for this link. See go/unsafe-pie."),
+ segment_size, target->max_pie_data_segment_size());
+ const_cast<General_options*>(&parameters->options())->set_pie_value(false);
+ }
+ }
+
+ // Finalize the .eh_frame section.
+ layout->finalize_eh_frame_section();
+
/* If plugins have specified a section order, re-arrange input sections
according to a specified section order. If --section-ordering-file is
also specified, do not do anything here. */
@@ -586,14 +641,6 @@ queue_middle_tasks(const General_options& options,
}
}
- // We have to support the case of not seeing any input objects, and
- // generate an empty file. Existing builds depend on being able to
- // pass an empty archive to the linker and get an empty object file
- // out. In order to do this we need to use a default target.
- if (input_objects->number_of_input_objects() == 0
- && layout->incremental_base() == NULL)
- parameters_force_valid_target();
-
int thread_count = options.thread_count_middle();
if (thread_count == 0)
thread_count = std::max(2, input_objects->number_of_input_objects());
@@ -672,9 +719,6 @@ queue_middle_tasks(const General_options& options,
// Define symbols from any linker scripts.
layout->define_script_symbols(symtab);
- // TODO(csilvers): figure out a more principled way to get the target
- Target* target = const_cast<Target*>(&parameters->target());
-
// Attach sections to segments.
layout->attach_sections_to_segments(target);