From 535890bb6466aa82b46ea191a37e75b8936aa913 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 11 Dec 2007 23:30:52 +0000 Subject: [PATCH] From Cary Coutant: Set DF_STATIC_TLS as appropriate. --- gold/i386.cc | 4 ++++ gold/layout.cc | 5 ++++- gold/layout.h | 12 ++++++++++++ gold/x86_64.cc | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gold/i386.cc b/gold/i386.cc index 38ea0ccbaf0..76719107b1e 100644 --- a/gold/i386.cc +++ b/gold/i386.cc @@ -973,6 +973,7 @@ Target_i386::Scan::local(const General_options&, case elfcpp::R_386_TLS_IE: // Initial-exec case elfcpp::R_386_TLS_IE_32: case elfcpp::R_386_TLS_GOTIE: + layout->set_has_static_tls(); if (optimized_type == tls::TLSOPT_NONE) { // For the R_386_TLS_IE relocation, we need to create a @@ -1005,6 +1006,7 @@ Target_i386::Scan::local(const General_options&, case elfcpp::R_386_TLS_LE: // Local-exec case elfcpp::R_386_TLS_LE_32: + layout->set_has_static_tls(); if (output_is_shared) { // We need to create a dynamic relocation. @@ -1275,6 +1277,7 @@ Target_i386::Scan::global(const General_options& options, case elfcpp::R_386_TLS_IE: // Initial-exec case elfcpp::R_386_TLS_IE_32: case elfcpp::R_386_TLS_GOTIE: + layout->set_has_static_tls(); if (optimized_type == tls::TLSOPT_NONE) { // For the R_386_TLS_IE relocation, we need to create a @@ -1304,6 +1307,7 @@ Target_i386::Scan::global(const General_options& options, case elfcpp::R_386_TLS_LE: // Local-exec case elfcpp::R_386_TLS_LE_32: + layout->set_has_static_tls(); if (parameters->output_is_shared()) { // We need to create a dynamic relocation. diff --git a/gold/layout.cc b/gold/layout.cc index 0a08f71d8cf..26585fa88c8 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -71,7 +71,8 @@ Layout::Layout(const General_options& options) eh_frame_section_(NULL), output_file_size_(-1), input_requires_executable_stack_(false), input_with_gnu_stack_note_(false), - input_without_gnu_stack_note_(false) + input_without_gnu_stack_note_(false), + has_static_tls_(false) { // Make space for more than enough segments for a typical file. // This is just for efficiency--it's OK if we wind up needing more. @@ -1733,6 +1734,8 @@ Layout::finish_dynamic_section(const Input_objects* input_objects, odyn->add_constant(elfcpp::DT_TEXTREL, 0); flags |= elfcpp::DF_TEXTREL; } + if (parameters->output_is_shared() && this->has_static_tls()) + flags |= elfcpp::DF_STATIC_TLS; odyn->add_constant(elfcpp::DT_FLAGS, flags); } diff --git a/gold/layout.h b/gold/layout.h index 12f703f70c1..37a70db50e2 100644 --- a/gold/layout.h +++ b/gold/layout.h @@ -226,6 +226,16 @@ class Layout find_output_segment(elfcpp::PT type, elfcpp::Elf_Word set, elfcpp::Elf_Word clear) const; + // Set a flag to indicate that an object file uses the static TLS model. + void + set_has_static_tls() + { this->has_static_tls_ = true; } + + // Return true if any object file uses the static TLS model. + bool + has_static_tls() const + { return this->has_static_tls_; } + // Dump statistical information to stderr. void print_stats() const; @@ -460,6 +470,8 @@ class Layout // Whether we have seen at least one object file without an // executable stack marker. bool input_without_gnu_stack_note_; + // Whether we have seen an object file that uses the static TLS model. + bool has_static_tls_; }; // This task handles writing out data in output sections which is not diff --git a/gold/x86_64.cc b/gold/x86_64.cc index f25a107fe8c..6df501d7b9b 100644 --- a/gold/x86_64.cc +++ b/gold/x86_64.cc @@ -942,6 +942,7 @@ Target_x86_64::Scan::local(const General_options&, break; case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec + layout->set_has_static_tls(); if (optimized_type == tls::TLSOPT_NONE) { // Create a GOT entry for the tp-relative offset. @@ -957,6 +958,7 @@ Target_x86_64::Scan::local(const General_options&, break; case elfcpp::R_X86_64_TPOFF32: // Local-exec + layout->set_has_static_tls(); if (output_is_shared) unsupported_reloc_local(object, r_type); break; @@ -1219,6 +1221,7 @@ Target_x86_64::Scan::global(const General_options& options, break; case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec + layout->set_has_static_tls(); if (optimized_type == tls::TLSOPT_NONE) { // Create a GOT entry for the tp-relative offset. @@ -1233,6 +1236,7 @@ Target_x86_64::Scan::global(const General_options& options, break; case elfcpp::R_X86_64_TPOFF32: // Local-exec + layout->set_has_static_tls(); if (parameters->output_is_shared()) unsupported_reloc_local(object, r_type); break;