From 158600eb989bcbc364c6d18259f1cb32ea9dc478 Mon Sep 17 00:00:00 2001 From: Cary Coutant Date: Wed, 15 Feb 2017 00:25:29 -0800 Subject: Disallow --incremental with -pie and force -no-pie for incremental tests. This is a partial fix for the gold testsuite failures documented in PR 21090. The use of -fpie triggers some mov-to-lea optimizations that are not compatible with incremental linking, so those optimizations need to be disabled. We also diagnose the attempt to use -pie with incremental linking, and force -no-pie for the incremental tests in case the build has been configured to have GCC pass -pie all the time. We still have a problem where compiling with -fpie results in some GOT entries even when linking with -no-pie. This combination still causes test failures because we are not updating the GOT entries in an incremental update link. gold/ PR gold/21090 * incremental.cc (Sized_relobj_incr::do_relocate): Fix comment. * options.cc (General_options::finalize): Disallow -pie with incremental linking. * x86_64.cc (Target_x86_64::Scan::local): Don't do mov-to-lea or callq-to-direct optimizations for incremental links. (Target_x86_64::Scan::global): Likewise. (Target_x86_64::Relocate::relocate): Likewise. * testsuite/Makefile.am (incremental_test): Force -no-pie. (incremental_test_2): Likewise. (incremental_test_3): Likewise. (incremental_test_4): Likewise. (incremental_test_5): Likewise. (incremental_test_6): Likewise. (incremental_copy_test): Likewise. (incremental_common_test_1): Likewise. (incremental_comdat_test_1): Likewise. * testsuite/Makefile.in: Regenerate. --- gold/x86_64.cc | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'gold/x86_64.cc') diff --git a/gold/x86_64.cc b/gold/x86_64.cc index da5087f..c837595 100644 --- a/gold/x86_64.cc +++ b/gold/x86_64.cc @@ -3066,9 +3066,10 @@ Target_x86_64::Scan::local(Symbol_table* symtab, // mov foo@GOTPCREL(%rip), %reg // to lea foo(%rip), %reg. // in Relocate::relocate. - if ((r_type == elfcpp::R_X86_64_GOTPCREL - || r_type == elfcpp::R_X86_64_GOTPCRELX - || r_type == elfcpp::R_X86_64_REX_GOTPCRELX) + if (!parameters->incremental() + && (r_type == elfcpp::R_X86_64_GOTPCREL + || r_type == elfcpp::R_X86_64_GOTPCRELX + || r_type == elfcpp::R_X86_64_REX_GOTPCRELX) && reloc.get_r_offset() >= 2 && !is_ifunc) { @@ -3079,7 +3080,6 @@ Target_x86_64::Scan::local(Symbol_table* symtab, break; } - // The symbol requires a GOT entry. unsigned int r_sym = elfcpp::elf_r_sym(reloc.get_r_info()); @@ -3546,15 +3546,21 @@ Target_x86_64::Scan::global(Symbol_table* symtab, // (callq|jmpq) *foo@GOTPCRELX(%rip) to // (callq|jmpq) foo // in Relocate::relocate, then there is nothing to do here. + // We cannot make these optimizations in incremental linking mode, + // because we look at the opcode to decide whether or not to make + // change, and during an incremental update, the change may have + // already been applied. Lazy_view view(object, data_shndx); size_t r_offset = reloc.get_r_offset(); - if (r_offset >= 2 + if (!parameters->incremental() + && r_offset >= 2 && Target_x86_64::can_convert_mov_to_lea(gsym, r_type, r_offset, &view)) break; - if (r_offset >= 2 + if (!parameters->incremental() + && r_offset >= 2 && Target_x86_64::can_convert_callq_to_direct(gsym, r_type, r_offset, &view)) @@ -4243,14 +4249,15 @@ Target_x86_64::Relocate::relocate( // mov foo@GOTPCREL(%rip), %reg // to lea foo(%rip), %reg. // if possible. - if ((gsym == NULL - && rela.get_r_offset() >= 2 - && view[-2] == 0x8b - && !psymval->is_ifunc_symbol()) - || (gsym != NULL - && rela.get_r_offset() >= 2 - && Target_x86_64::can_convert_mov_to_lea(gsym, r_type, - 0, &view))) + if (!parameters->incremental() + && ((gsym == NULL + && rela.get_r_offset() >= 2 + && view[-2] == 0x8b + && !psymval->is_ifunc_symbol()) + || (gsym != NULL + && rela.get_r_offset() >= 2 + && Target_x86_64::can_convert_mov_to_lea(gsym, r_type, + 0, &view)))) { view[-2] = 0x8d; Reloc_funcs::pcrela32(view, object, psymval, addend, address); @@ -4261,7 +4268,8 @@ Target_x86_64::Relocate::relocate( // and jmpq *foo@GOTPCRELX(%rip) to // jmpq foo // nop - else if (gsym != NULL + else if (!parameters->incremental() + && gsym != NULL && rela.get_r_offset() >= 2 && Target_x86_64::can_convert_callq_to_direct(gsym, r_type, -- cgit v1.1