From 3481085102449795e77ce56d628a10e931bde4be Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 22 Jul 2008 23:55:24 +0000 Subject: [PATCH] * options.h (class General_options): Define --check-sections. * layout.cc (Layout::set_segment_offsets): Handle --check-sections. --- gold/ChangeLog | 4 ++++ gold/layout.cc | 22 ++++++++++++++++++++++ gold/options.h | 4 ++++ 3 files changed, 30 insertions(+) diff --git a/gold/ChangeLog b/gold/ChangeLog index 372c8d9..6fb10a1 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,5 +1,9 @@ 2008-07-22 Ian Lance Taylor + * options.h (class General_options): Define --check-sections. + * layout.cc (Layout::set_segment_offsets): Handle + --check-sections. + * options.h (class General_options): Define -n/--nmagic and -N/--omagic. * options.cc (General_options::finalize): For -n/--nmagic or diff --git a/gold/layout.cc b/gold/layout.cc index 8c7cd99..37edbb6c 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -1732,6 +1732,9 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg, } } + const bool check_sections = parameters->options().check_sections(); + Output_segment* last_load_segment = NULL; + bool was_readonly = false; for (Segment_list::iterator p = this->segment_list_.begin(); p != this->segment_list_.end(); @@ -1848,6 +1851,25 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg, if (((*p)->flags() & elfcpp::PF_W) == 0) was_readonly = true; + + // Implement --check-sections. We know that the segments + // are sorted by LMA. + if (check_sections && last_load_segment != NULL) + { + gold_assert(last_load_segment->paddr() <= (*p)->paddr()); + if (last_load_segment->paddr() + last_load_segment->memsz() + > (*p)->paddr()) + { + unsigned long long lb1 = last_load_segment->paddr(); + unsigned long long le1 = lb1 + last_load_segment->memsz(); + unsigned long long lb2 = (*p)->paddr(); + unsigned long long le2 = lb2 + (*p)->memsz(); + gold_error(_("load segment overlap [0x%llx -> 0x%llx] and " + "[0x%llx -> 0x%llx]"), + lb1, le1, lb2, le2); + } + } + last_load_segment = *p; } } diff --git a/gold/options.h b/gold/options.h index 91f9552..6a456f1 100644 --- a/gold/options.h +++ b/gold/options.h @@ -576,6 +576,10 @@ class General_options N_("Generate build ID note"), N_("[=STYLE]")); + DEFINE_bool(check_sections, options::TWO_DASHES, '\0', true, + N_("Check segment addresses for overlaps (default)"), + N_("Do not check segment addresses for overlaps")); + #ifdef HAVE_ZLIB_H DEFINE_enum(compress_debug_sections, options::TWO_DASHES, '\0', "none", N_("Compress .debug_* sections in the output file"), -- 2.7.4