Index: README =================================================================== RCS file: /cvs/src/src/gold/README,v retrieving revision 1.3 diff -p -u -r1.3 README --- README 28 Feb 2009 18:08:30 -0000 1.3 +++ README 14 Oct 2009 05:22:55 -0000 @@ -18,7 +18,6 @@ gold--are: * MEMORY regions in linker scripts * MRI compatible linker scripts * cross-reference reports (--cref) - * position independent executables (-pie) * various other minor options Index: gold.cc =================================================================== RCS file: /cvs/src/src/gold/gold.cc,v retrieving revision 1.72 diff -p -u -r1.72 gold.cc --- gold.cc 13 Oct 2009 21:17:43 -0000 1.72 +++ gold.cc 14 Oct 2009 05:22:55 -0000 @@ -396,8 +396,9 @@ queue_middle_tasks(const General_options workqueue->set_thread_count(thread_count); // Now we have seen all the input files. - const bool doing_static_link = (!input_objects->any_dynamic() - && !parameters->options().shared()); + const bool doing_static_link = + (!input_objects->any_dynamic() + && !parameters->options().output_is_position_independent()); set_parameters_doing_static_link(doing_static_link); if (!doing_static_link && options.is_static()) { Index: i386.cc =================================================================== RCS file: /cvs/src/src/gold/i386.cc,v retrieving revision 1.93 diff -p -u -r1.93 i386.cc --- i386.cc 13 Oct 2009 00:39:31 -0000 1.93 +++ i386.cc 14 Oct 2009 05:22:55 -0000 @@ -692,7 +692,7 @@ Output_data_plt_i386::do_write(Output_fi elfcpp::Elf_types<32>::Elf_Addr plt_address = this->address(); elfcpp::Elf_types<32>::Elf_Addr got_address = this->got_plt_->address(); - if (parameters->options().shared()) + if (parameters->options().output_is_position_independent()) memcpy(pov, dyn_first_plt_entry, plt_entry_size); else { @@ -724,7 +724,7 @@ Output_data_plt_i386::do_write(Output_fi { // Set and adjust the PLT entry itself. - if (parameters->options().shared()) + if (parameters->options().output_is_position_independent()) { memcpy(pov, dyn_plt_entry, plt_entry_size); elfcpp::Swap_unaligned<32, false>::writeval(pov + 2, got_offset); Index: layout.cc =================================================================== RCS file: /cvs/src/src/gold/layout.cc,v retrieving revision 1.138 diff -p -u -r1.138 layout.cc --- layout.cc 13 Oct 2009 21:23:00 -0000 1.138 +++ layout.cc 14 Oct 2009 05:22:56 -0000 @@ -2144,7 +2144,7 @@ Layout::set_segment_offsets(const Target uint64_t addr; if (parameters->options().user_set_Ttext()) addr = parameters->options().Ttext(); - else if (parameters->options().shared()) + else if (parameters->options().output_is_position_independent()) addr = 0; else addr = target->default_text_segment_address(); Index: options.cc =================================================================== RCS file: /cvs/src/src/gold/options.cc,v retrieving revision 1.93 diff -p -u -r1.93 options.cc --- options.cc 13 Oct 2009 21:17:43 -0000 1.93 +++ options.cc 14 Oct 2009 05:22:57 -0000 @@ -1001,17 +1001,24 @@ General_options::finalize() // Now that we've normalized the options, check for contradictory ones. if (this->shared() && this->is_static()) gold_fatal(_("-shared and -static are incompatible")); + if (this->shared() && this->pie()) + gold_fatal(_("-shared and -pie are incompatible")); if (this->shared() && this->relocatable()) gold_fatal(_("-shared and -r are incompatible")); + if (this->pie() && this->relocatable()) + gold_fatal(_("-pie and -r are incompatible")); // TODO: implement support for -retain-symbols-file with -r, if needed. if (this->relocatable() && this->retain_symbols_file()) gold_fatal(_("-retain-symbols-file does not yet work with -r")); if (this->oformat_enum() != General_options::OBJECT_FORMAT_ELF - && (this->shared() || this->relocatable())) - gold_fatal(_("binary output format not compatible with -shared or -r")); + && (this->shared() + || this->pie() + || this->relocatable())) + gold_fatal(_("binary output format not compatible " + "with -shared or -pie or -r")); if (this->user_set_hash_bucket_empty_fraction() && (this->hash_bucket_empty_fraction() < 0.0 Index: options.h =================================================================== RCS file: /cvs/src/src/gold/options.h,v retrieving revision 1.113 diff -p -u -r1.113 options.h --- options.h 13 Oct 2009 21:23:00 -0000 1.113 +++ options.h 14 Oct 2009 05:22:57 -0000 @@ -763,6 +763,12 @@ class General_options DEFINE_string(oformat, options::EXACTLY_TWO_DASHES, '\0', "elf", N_("Set output format"), N_("[binary]")); + DEFINE_bool(pie, options::ONE_DASH, '\0', false, + N_("Create a position independent executable"), NULL); + DEFINE_bool_alias(pic_executable, pie, options::TWO_DASHES, '\0', + N_("Create a position independent executable"), NULL, + false); + #ifdef ENABLE_PLUGINS DEFINE_special(plugin, options::TWO_DASHES, '\0', N_("Load a plugin library"), N_("PLUGIN")); @@ -1009,7 +1015,7 @@ class General_options // the output is position-independent or not. bool output_is_position_independent() const - { return this->shared(); } + { return this->shared() || this->pie(); } // Return true if the output is something that can be exec()ed, such // as a static executable, or a position-dependent or @@ -1017,13 +1023,7 @@ class General_options // object file. bool output_is_executable() const - { return !this->shared() || this->output_is_pie(); } - - // Return true if the output is a position-independent executable. - // This is currently not supported. - bool - output_is_pie() const - { return false; } + { return !this->shared() && !this->relocatable(); } // This would normally be static(), and defined automatically, but // since static is a keyword, we need to come up with our own name. Index: output.cc =================================================================== RCS file: /cvs/src/src/gold/output.cc,v retrieving revision 1.98 diff -p -u -r1.98 output.cc --- output.cc 9 Oct 2009 23:18:19 -0000 1.98 +++ output.cc 14 Oct 2009 05:22:58 -0000 @@ -442,7 +442,7 @@ Output_file_header::do_sized_write(Outpu elfcpp::ET e_type; if (parameters->options().relocatable()) e_type = elfcpp::ET_REL; - else if (parameters->options().shared()) + else if (parameters->options().output_is_position_independent()) e_type = elfcpp::ET_DYN; else e_type = elfcpp::ET_EXEC; Index: symtab.cc =================================================================== RCS file: /cvs/src/src/gold/symtab.cc,v retrieving revision 1.125 diff -p -u -r1.125 symtab.cc --- symtab.cc 13 Oct 2009 21:17:43 -0000 1.125 +++ symtab.cc 14 Oct 2009 05:23:00 -0000 @@ -394,7 +394,8 @@ Symbol::final_value_is_known() const { // If we are not generating an executable, then no final values are // known, since they will change at runtime. - if (parameters->options().shared() || parameters->options().relocatable()) + if (parameters->options().output_is_position_independent() + || parameters->options().relocatable()) return false; // If the symbol is not from an object file, and is not undefined, Index: symtab.h =================================================================== RCS file: /cvs/src/src/gold/symtab.h,v retrieving revision 1.94 diff -p -u -r1.94 symtab.h --- symtab.h 13 Oct 2009 00:39:31 -0000 1.94 +++ symtab.h 14 Oct 2009 05:23:00 -0000 @@ -533,7 +533,7 @@ class Symbol // Return true if this symbol is a function that needs a PLT entry. // If the symbol is defined in a dynamic object or if it is subject // to pre-emption, we need to make a PLT entry. If we're doing a - // static link, we don't create PLT entries. + // static link or a -pie link, we don't create PLT entries. bool needs_plt_entry() const { @@ -542,6 +542,7 @@ class Symbol return false; return (!parameters->doing_static_link() + && !parameters->options().pie() && this->type() == elfcpp::STT_FUNC && (this->is_from_dynobj() || this->is_undefined() Index: testsuite/Makefile.am =================================================================== RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v retrieving revision 1.106 diff -p -u -r1.106 Makefile.am --- testsuite/Makefile.am 13 Oct 2009 21:17:43 -0000 1.106 +++ testsuite/Makefile.am 14 Oct 2009 05:23:01 -0000 @@ -176,6 +176,11 @@ basic_pic_test: basic_pic_test.o gcctest basic_static_pic_test: basic_pic_test.o gcctestdir/ld $(CXXLINK) -Bgcctestdir/ -static basic_pic_test.o +check_PROGRAMS += basic_pie_test +basic_pie_test.o: basic_test.cc + $(CXXCOMPILE) -O0 -c -fpie -o $@ $< +basic_pie_test: basic_pie_test.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ -pie basic_pie_test.o check_PROGRAMS += constructor_test check_PROGRAMS += constructor_static_test @@ -281,6 +286,19 @@ two_file_relocatable_test_LDADD = two_fi two_file_relocatable.o: gcctestdir/ld two_file_test_1.o two_file_test_1b.o two_file_test_2.o gcctestdir/ld -r -o $@ two_file_test_1.o two_file_test_1b.o two_file_test_2.o +check_PROGRAMS += two_file_pie_test +two_file_test_1_pie.o: two_file_test_1.cc + $(CXXCOMPILE) -c -fpie -o $@ $< +two_file_test_1b_pie.o: two_file_test_1b.cc + $(CXXCOMPILE) -c -fpie -o $@ $< +two_file_test_2_pie.o: two_file_test_2.cc + $(CXXCOMPILE) -c -fpie -o $@ $< +two_file_test_main_pie.o: two_file_test_main.cc + $(CXXCOMPILE) -c -fpie -o $@ $< +two_file_pie_test: two_file_test_1_pie.o two_file_test_1b_pie.o \ + two_file_test_2_pie.o two_file_test_main_pie.o gcctestdir/ld + $(CXXLINK) -Bgcctestdir/ -pie two_file_test_1_pie.o two_file_test_1b_pie.o two_file_test_2_pie.o two_file_test_main_pie.o + check_SCRIPTS += two_file_shared.sh check_DATA += two_file_shared.dbg MOSTLYCLEANFILES += two_file_shared.dbg