Commit 4e6a9380 by Jan Hubicka Committed by Jan Hubicka

re PR lto/86517 (relocation R_X86_64_32 against `.rodata.str1.1' can not be used…

re PR lto/86517 (relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object with LTO)



	PR lto/86517
	* lto-opts.c (lto_write_options): Always stream PIC/PIE mode.
	* lto-wrapper.c (merge_and_complain): Fix merging of PIC/PIE.

From-SVN: r263988
parent 24c35f68
2018-08-29 Jan Hubicka <jh@suse.cz> 2018-08-29 Jan Hubicka <jh@suse.cz>
PR lto/86517
* lto-opts.c (lto_write_options): Always stream PIC/PIE mode.
* lto-wrapper.c (merge_and_complain): Fix merging of PIC/PIE.
2018-08-29 Jan Hubicka <jh@suse.cz>
* lto-streamer-out.c (DFS::DFS_write_tree_body): Do not follow * lto-streamer-out.c (DFS::DFS_write_tree_body): Do not follow
TYPE_STUB_DECL. TYPE_STUB_DECL.
(hash_tree): Do not visit TYPE_STUB_DECL. (hash_tree): Do not visit TYPE_STUB_DECL.
......
...@@ -78,6 +78,21 @@ lto_write_options (void) ...@@ -78,6 +78,21 @@ lto_write_options (void)
&& !global_options.x_flag_openacc) && !global_options.x_flag_openacc)
append_to_collect_gcc_options (&temporary_obstack, &first_p, append_to_collect_gcc_options (&temporary_obstack, &first_p,
"-fno-openacc"); "-fno-openacc");
/* Append PIC/PIE mode because its default depends on target and it is
subject of merging in lto-wrapper. */
if (!global_options_set.x_flag_pic && !global_options_set.x_flag_pie)
{
append_to_collect_gcc_options (&temporary_obstack, &first_p,
global_options.x_flag_pic == 2
? "-fPIC"
: global_options.x_flag_pic == 1
? "-fpic"
: global_options.x_flag_pie == 2
? "-fPIE"
: global_options.x_flag_pie == 1
? "-fpie"
: "-fno-pie");
}
/* Append options from target hook and store them to offload_lto section. */ /* Append options from target hook and store them to offload_lto section. */
if (lto_stream_offload_p) if (lto_stream_offload_p)
......
...@@ -409,6 +409,11 @@ merge_and_complain (struct cl_decoded_option **decoded_options, ...@@ -409,6 +409,11 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
It is a common mistake to mix few -fPIC compiled objects into otherwise It is a common mistake to mix few -fPIC compiled objects into otherwise
non-PIC code. We do not want to build everything with PIC then. non-PIC code. We do not want to build everything with PIC then.
Similarly we merge PIE options, however in addition we keep
-fPIC + -fPIE = -fPIE
-fpic + -fPIE = -fpie
-fPIC/-fpic + -fpie = -fpie
It would be good to warn on mismatches, but it is bit hard to do as It would be good to warn on mismatches, but it is bit hard to do as
we do not know what nothing translates to. */ we do not know what nothing translates to. */
...@@ -416,11 +421,38 @@ merge_and_complain (struct cl_decoded_option **decoded_options, ...@@ -416,11 +421,38 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
if ((*decoded_options)[j].opt_index == OPT_fPIC if ((*decoded_options)[j].opt_index == OPT_fPIC
|| (*decoded_options)[j].opt_index == OPT_fpic) || (*decoded_options)[j].opt_index == OPT_fpic)
{ {
if (!pic_option /* -fno-pic in one unit implies -fno-pic everywhere. */
|| (pic_option->value > 0) != ((*decoded_options)[j].value > 0)) if ((*decoded_options)[j].value == 0)
remove_option (decoded_options, j, decoded_options_count); j++;
else if (pic_option->opt_index == OPT_fPIC /* If we have no pic option or merge in -fno-pic, we still may turn
&& (*decoded_options)[j].opt_index == OPT_fpic) existing pic/PIC mode into pie/PIE if -fpie/-fPIE is present. */
else if ((pic_option && pic_option->value == 0)
|| !pic_option)
{
if (pie_option)
{
bool big = (*decoded_options)[j].opt_index == OPT_fPIC
&& pie_option->opt_index == OPT_fPIE;
(*decoded_options)[j].opt_index = big ? OPT_fPIE : OPT_fpie;
if (pie_option->value)
(*decoded_options)[j].canonical_option[0] = big ? "-fPIE" : "-fpie";
else
(*decoded_options)[j].canonical_option[0] = big ? "-fno-pie" : "-fno-pie";
(*decoded_options)[j].value = pie_option->value;
j++;
}
else if (pic_option)
{
(*decoded_options)[j] = *pic_option;
j++;
}
/* We do not know if target defaults to pic or not, so just remove
option if it is missing in one unit but enabled in other. */
else
remove_option (decoded_options, j, decoded_options_count);
}
else if (pic_option->opt_index == OPT_fpic
&& (*decoded_options)[j].opt_index == OPT_fPIC)
{ {
(*decoded_options)[j] = *pic_option; (*decoded_options)[j] = *pic_option;
j++; j++;
...@@ -431,11 +463,42 @@ merge_and_complain (struct cl_decoded_option **decoded_options, ...@@ -431,11 +463,42 @@ merge_and_complain (struct cl_decoded_option **decoded_options,
else if ((*decoded_options)[j].opt_index == OPT_fPIE else if ((*decoded_options)[j].opt_index == OPT_fPIE
|| (*decoded_options)[j].opt_index == OPT_fpie) || (*decoded_options)[j].opt_index == OPT_fpie)
{ {
if (!pie_option /* -fno-pie in one unit implies -fno-pie everywhere. */
|| pie_option->value != (*decoded_options)[j].value) if ((*decoded_options)[j].value == 0)
remove_option (decoded_options, j, decoded_options_count); j++;
else if (pie_option->opt_index == OPT_fPIE /* If we have no pie option or merge in -fno-pie, we still preserve
&& (*decoded_options)[j].opt_index == OPT_fpie) PIE/pie if pic/PIC is present. */
else if ((pie_option && pie_option->value == 0)
|| !pie_option)
{
/* If -fPIC/-fpic is given, merge it with -fPIE/-fpie. */
if (pic_option)
{
if (pic_option->opt_index == OPT_fpic
&& (*decoded_options)[j].opt_index == OPT_fPIE)
{
(*decoded_options)[j].opt_index = OPT_fpie;
(*decoded_options)[j].canonical_option[0]
= pic_option->value ? "-fpie" : "-fno-pie";
}
else if (!pic_option->value)
(*decoded_options)[j].canonical_option[0] = "-fno-pie";
(*decoded_options)[j].value = pic_option->value;
j++;
}
else if (pie_option)
{
(*decoded_options)[j] = *pie_option;
j++;
}
/* Because we always append pic/PIE options this code path should
not happen unless the LTO object was built by old lto1 which
did not contain that logic yet. */
else
remove_option (decoded_options, j, decoded_options_count);
}
else if (pie_option->opt_index == OPT_fpie
&& (*decoded_options)[j].opt_index == OPT_fPIE)
{ {
(*decoded_options)[j] = *pie_option; (*decoded_options)[j] = *pie_option;
j++; j++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment