Bug 87833 - [8/9/10 Regression] -fPIC isn't used to create offload shared library
Summary: [8/9/10 Regression] -fPIC isn't used to create offload shared library
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.4
Assignee: Thomas Schwinge
URL:
Keywords: openmp
Depends on:
Blocks:
 
Reported: 2018-10-31 17:00 UTC by Thomas Schwinge
Modified: 2019-11-11 09:41 UTC (History)
3 users (show)

See Also:
Host:
Target: x86_64-intelmicemul-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-11-11 00:00:00


Attachments
WIP patch/work around (589 bytes, patch)
2018-10-31 17:00 UTC, Thomas Schwinge
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schwinge 2018-10-31 17:00:46 UTC
Created attachment 44937 [details]
WIP patch/work around

Commit r263988 (for PR86517 "relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object with LTO") makes a lot of (or even all?) Intel MIC offloading test cases fail to compile:

    [...]/ld: /tmp/ccCCZyfF.o: relocation R_X86_64_32S against `[...]' can not be used when making a shared object; recompile with -fPIC
    /tmp/ccCCZyfF.o: error adding symbols: Bad value
    mkoffload-intelmic: fatal error: [...]

I have not yet analyzed what's actually going wrong.  Before spending more time on this, I first wanted to make sure that's still useful -- given that in the past two months apparently nobody but me has run into this (or didn't bother to report it), and I thus wonder whether anyone but me is still testing Intel MIC (emulated) offloading?

No idea yet if the attached patch/hack is correct in any way, but it at least restores Intel MIC (emulated) offloading compilation.
Comment 1 H.J. Lu 2019-05-01 21:00:49 UTC
Do you have a testcase?
Comment 2 Thomas Schwinge 2019-05-02 09:04:21 UTC
(In reply to H.J. Lu from comment #1)
> Do you have a testcase?

Thought that would be obvious from the report.  Configure GCC for Intel MIC (emulated) offloading, then run the libgomp testsuite.
Comment 3 H.J. Lu 2019-05-02 14:41:21 UTC
(In reply to Thomas Schwinge from comment #2)
> (In reply to H.J. Lu from comment #1)
> > Do you have a testcase?
> 
> Thought that would be obvious from the report.  Configure GCC for Intel MIC
> (emulated) offloading, then run the libgomp testsuite.

Please provide your GCC configure options.
Comment 4 Jakub Jelinek 2019-05-02 14:44:58 UTC
See https://gcc.gnu.org/wiki/Offloading
Comment 5 H.J. Lu 2019-05-02 20:11:14 UTC
[hjl@gnu-cfl-1 pr87833]$ cat x.i
void open_fd(char *);

void init_ioctl_ctl() { open_fd(""); }
void get_ioctl_ops() {}
[hjl@gnu-cfl-1 pr87833]$ cat y.i
void get_ioctl_ops();
void a() {
    get_ioctl_ops();
}
[hjl@gnu-cfl-1 pr87833]$ make
/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/ -O2 -fPIC -c y.i
/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/ -O2 -fPIC -c x.i
/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/ -o x.so y.o x.o -shared -fPIC -fno-pie
[hjl@gnu-cfl-1 pr87833]$ make clean
rm -f *.o *.s foo bar *.[cCi].* x *.ii.* *.a
[hjl@gnu-cfl-1 pr87833]$ make LTO=1
/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/ -O2 -flto -fPIC -c y.i
/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/ -O2 -flto -fPIC -c x.i
/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/tools-build/gcc-debug/build-x86_64-linux/gcc/ -o x.so y.o x.o -shared -fPIC -fno-pie
/usr/local/bin/ld: /tmp/x.so.LWF6nG.ltrans0.ltrans.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make: *** [Makefile:21: x.so] Error 1
[hjl@gnu-cfl-1 pr87833]$ 

-fPIC -fno-pie should turn off PIE/pie, not PIC/pic.
Comment 6 H.J. Lu 2019-05-02 21:35:31 UTC
A patch is posted at

https://gcc.gnu.org/ml/gcc-patches/2019-05/msg00084.html
Comment 7 Thomas Schwinge 2019-11-11 08:37:34 UTC
On gcc-8-branch, as of r267610 (for PR86517, PR88185), this is now broken, too.


I'll commit H.J.'s patch.
Comment 8 Thomas Schwinge 2019-11-11 08:38:59 UTC
Author: tschwinge
Date: Mon Nov 11 08:38:28 2019
New Revision: 278041

URL: https://gcc.gnu.org/viewcvs?rev=278041&root=gcc&view=rev
Log:
[PR87833] x86: Put -fPIC and -shared the last to create offload image

On x86, since -fPIC and -shared should be used to create offload image,
we put them the last to properly create offload image.

2019-11-11  H.J. Lu  <hjl.tools@gmail.com>

	PR target/87833
	* config/i386/intelmic-mkoffload.c (prepare_target_image): Put
	-fPIC and -shared the last to create offload image.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/intelmic-mkoffload.c
Comment 9 Thomas Schwinge 2019-11-11 08:39:41 UTC
Author: tschwinge
Date: Mon Nov 11 08:39:10 2019
New Revision: 278042

URL: https://gcc.gnu.org/viewcvs?rev=278042&root=gcc&view=rev
Log:
[PR87833] x86: Put -fPIC and -shared the last to create offload image

On x86, since -fPIC and -shared should be used to create offload image,
we put them the last to properly create offload image.

2019-11-11  H.J. Lu  <hjl.tools@gmail.com>

	PR target/87833
	* config/i386/intelmic-mkoffload.c (prepare_target_image): Put
	-fPIC and -shared the last to create offload image.

Backport from trunk r278041.

Modified:
    branches/gcc-9-branch/gcc/ChangeLog
    branches/gcc-9-branch/gcc/config/i386/intelmic-mkoffload.c
Comment 10 Thomas Schwinge 2019-11-11 08:40:03 UTC
Author: tschwinge
Date: Mon Nov 11 08:39:32 2019
New Revision: 278043

URL: https://gcc.gnu.org/viewcvs?rev=278043&root=gcc&view=rev
Log:
[PR87833] x86: Put -fPIC and -shared the last to create offload image

On x86, since -fPIC and -shared should be used to create offload image,
we put them the last to properly create offload image.

2019-11-11  H.J. Lu  <hjl.tools@gmail.com>

	PR target/87833
	* config/i386/intelmic-mkoffload.c (prepare_target_image): Put
	-fPIC and -shared the last to create offload image.

Backport from trunk r278041.

Modified:
    branches/gcc-8-branch/gcc/ChangeLog
    branches/gcc-8-branch/gcc/config/i386/intelmic-mkoffload.c
Comment 11 Thomas Schwinge 2019-11-11 09:41:18 UTC
.