* Darwin linker error "illegal text-relocation" with -shared
@ 2018-04-16 16:18 Ryan S. Elliott
2018-04-16 18:20 ` Thomas Koenig
0 siblings, 1 reply; 7+ messages in thread
From: Ryan S. Elliott @ 2018-04-16 16:18 UTC (permalink / raw)
To: fortran
[-- Attachment #1: Type: text/plain, Size: 1816 bytes --]
Hello,
I would like to see if any progress can be made on the darwin linker error
reported in 2014 and documented here:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59888
This is a significant problem for the OpenKIM system (https://openkim.org)
which has many users who would like to use its kim-api package
(https://github.com/openkim/kim-api) and the associated "Model" codes available
at openkim.org with macOS.
We have been getting by with a work-around (compile for 32-bit architecture
"-m32" and use the "-read_only_relocs suppress" command line argument) but now
we would like to be able to provide precompiled binaries that will work with
other standard compiled software (i.e., 64-bit, etc.) through the homebrew
package management system.
Here is the minimal code snippet showing the problem and the compiler/linker
output.
----------------------------------------------
foo.f90
----------------------------------------------
module foo contains
subroutine bar
use, intrinsic :: iso_c_binding
call gee(c_funloc(gee))
end subroutine
subroutine gee(f) bind(c)
use, intrinsic :: iso_c_binding
type(c_funptr) :: f
end subroutine
end module foo
----------------------------------------------
$ gfortran-7 -shared foo.f90
ld: illegal text-relocation to '_gee' in
/var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccYs60h3.o from 'lC0' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccYs60h3.o for architecture x86_64
collect2: error: ld returned 1 exit status
$ gfortran-7 --version
GNU Fortran (Homebrew GCC 7.3.0_1) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Thanks,
Ryan S. Elliott
[-- Attachment #2: Type: text/plain, Size: 249 bytes --]
module foo
contains
subroutine bar
use, intrinsic :: iso_c_binding
call gee(c_funloc(gee))
end subroutine
subroutine gee(f) bind(c)
use, intrinsic :: iso_c_binding
type(c_funptr) :: f
end subroutine
end module foo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Darwin linker error "illegal text-relocation" with -shared
2018-04-16 16:18 Darwin linker error "illegal text-relocation" with -shared Ryan S. Elliott
@ 2018-04-16 18:20 ` Thomas Koenig
2018-04-16 19:35 ` Ryan S. Elliott
0 siblings, 1 reply; 7+ messages in thread
From: Thomas Koenig @ 2018-04-16 18:20 UTC (permalink / raw)
To: Ryan S. Elliott, fortran
Hello Ryan,
> foo.f90
> ----------------------------------------------
> module foo contains
> Â subroutine bar
> Â Â Â use, intrinsic :: iso_c_binding
> Â Â Â call gee(c_funloc(gee))
> Â end subroutine
> Â subroutine gee(f) bind(c)
> Â Â Â use, intrinsic :: iso_c_binding
> Â Â Â type(c_funptr) :: f
> Â end subroutine
> end module foo
> ----------------------------------------------
>
> $ gfortran-7 -shared foo.f90
You are invoking gfortran without the "-c" option, so it expects to
generate an executable. Yet, you specify "-shared", which only makes
sense for a library, and your source code does not contain a main
program.
What happens if you run
"gfortran -c -shared foo.f90" ?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Darwin linker error "illegal text-relocation" with -shared
2018-04-16 18:20 ` Thomas Koenig
@ 2018-04-16 19:35 ` Ryan S. Elliott
2018-04-16 19:46 ` Thomas Koenig
0 siblings, 1 reply; 7+ messages in thread
From: Ryan S. Elliott @ 2018-04-16 19:35 UTC (permalink / raw)
To: Thomas Koenig; +Cc: fortran
[-- Attachment #1: Type: text/plain, Size: 1139 bytes --]
On Mon, 16 Apr 2018, Thomas Koenig wrote:
> Hello Ryan,
>
>> foo.f90
>> ----------------------------------------------
>> module foo contains
>> Â subroutine bar
>> Â Â Â use, intrinsic :: iso_c_binding
>> Â Â Â call gee(c_funloc(gee))
>> Â end subroutine
>> Â subroutine gee(f) bind(c)
>> Â Â Â use, intrinsic :: iso_c_binding
>> Â Â Â type(c_funptr) :: f
>> Â end subroutine
>> end module foo
>> ----------------------------------------------
>>
>> $ gfortran-7 -shared foo.f90
>
> You are invoking gfortran without the "-c" option, so it expects to
> generate an executable. Yet, you specify "-shared", which only makes
> sense for a library, and your source code does not contain a main
> program.
>
> What happens if you run
>
> "gfortran -c -shared foo.f90" ?
Hello, Thanks for your message.
Your suggestion does not generate an error, but only because it does not invoke
the linker in order to create a shared library. It just creates a .mod and .o
file.
In other words, the -c flag overrides the -shared flag. This is not what I
want. I want to create a shared library which is done by the linker.
Ryan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Darwin linker error "illegal text-relocation" with -shared
2018-04-16 19:35 ` Ryan S. Elliott
@ 2018-04-16 19:46 ` Thomas Koenig
2018-04-16 19:51 ` Ryan S. Elliott
0 siblings, 1 reply; 7+ messages in thread
From: Thomas Koenig @ 2018-04-16 19:46 UTC (permalink / raw)
To: Ryan S. Elliott; +Cc: fortran
OK, so I haven't played around with shared libraries a lot.
> In other words, the -c flag overrides the -shared flag. This is not
> what I want. I want to create a shared library which is done by the
> linker.
When I run "gfortran -shared foo.f90" on Linux, I get
/usr/bin/ld: /tmp/ccixEBK9.o: relocation R_X86_64_32 against `.rodata'
can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: Fehler: ld gab 1 als Ende-Status zurück
whereas "gfortran -shared -fPIC foo.f90" works.
Is it advisable to compile a shared library without position-independent
code?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Darwin linker error "illegal text-relocation" with -shared
2018-04-16 19:46 ` Thomas Koenig
@ 2018-04-16 19:51 ` Ryan S. Elliott
2018-04-16 20:14 ` Steve Kargl
0 siblings, 1 reply; 7+ messages in thread
From: Ryan S. Elliott @ 2018-04-16 19:51 UTC (permalink / raw)
To: Thomas Koenig; +Cc: fortran
[-- Attachment #1: Type: text/plain, Size: 1225 bytes --]
On Mon, 16 Apr 2018, Thomas Koenig wrote:
> OK, so I haven't played around with shared libraries a lot.
>
>> In other words, the -c flag overrides the -shared flag. This is not what I
>> want. I want to create a shared library which is done by the linker.
>
> When I run "gfortran -shared foo.f90" on Linux, I get
>
> /usr/bin/ld: /tmp/ccixEBK9.o: relocation R_X86_64_32 against `.rodata' can
> not be used when making a shared object; recompile with -fPIC
> /usr/bin/ld: final link failed: Nonrepresentable section on output
> collect2: Fehler: ld gab 1 als Ende-Status zurück
>
> whereas "gfortran -shared -fPIC foo.f90" works.
>
> Is it advisable to compile a shared library without position-independent
> code?
>
No, you are right. I should have included the -fPIC flag, but this doesn't
change the results:
$ gfortran-7 -shared -fPIC foo.f90
ld: illegal text-relocation to '_gee' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccG1nHc0.o from 'lC0' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccG1nHc0.o for architecture x86_64
collect2: error: ld returned 1 exit status
As indicated in the subject linek, this is only an issue on macOS (Darwin), it
all works just fine on linux...
Ryan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Darwin linker error "illegal text-relocation" with -shared
2018-04-16 19:51 ` Ryan S. Elliott
@ 2018-04-16 20:14 ` Steve Kargl
2018-04-16 21:09 ` Ryan S. Elliott
0 siblings, 1 reply; 7+ messages in thread
From: Steve Kargl @ 2018-04-16 20:14 UTC (permalink / raw)
To: Ryan S. Elliott; +Cc: Thomas Koenig, fortran
On Mon, Apr 16, 2018 at 02:51:16PM -0500, Ryan S. Elliott wrote:
>
> No, you are right. I should have included the -fPIC flag, but this doesn't
> change the results:
>
>
> $ gfortran-7 -shared -fPIC foo.f90
> ld: illegal text-relocation to '_gee' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccG1nHc0.o from 'lC0' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccG1nHc0.o for architecture x86_64
> collect2: error: ld returned 1 exit status
>
google 'macos ld illegal text-relocation' suggests that this
is a longstanding problem with macos. Perhaps, a bug report
to Apple is appropriate?
Try adding "-Wl,-read_only_relocs suppress" to your command line.
--
Steve
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Darwin linker error "illegal text-relocation" with -shared
2018-04-16 20:14 ` Steve Kargl
@ 2018-04-16 21:09 ` Ryan S. Elliott
0 siblings, 0 replies; 7+ messages in thread
From: Ryan S. Elliott @ 2018-04-16 21:09 UTC (permalink / raw)
To: Steve Kargl; +Cc: Thomas Koenig, fortran
On Mon, 16 Apr 2018, Steve Kargl wrote:
> On Mon, Apr 16, 2018 at 02:51:16PM -0500, Ryan S. Elliott wrote:
>>
>> No, you are right. I should have included the -fPIC flag, but this doesn't
>> change the results:
>>
>>
>> $ gfortran-7 -shared -fPIC foo.f90
>> ld: illegal text-relocation to '_gee' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccG1nHc0.o from 'lC0' in /var/folders/q0/mth73zrd307d66c43f8r3xv80000gp/T//ccG1nHc0.o for architecture x86_64
>> collect2: error: ld returned 1 exit status
>>
>
> google 'macos ld illegal text-relocation' suggests that this
> is a longstanding problem with macos. Perhaps, a bug report
> to Apple is appropriate?
>
> Try adding "-Wl,-read_only_relocs suppress" to your command line.
Yes, this is a long standing issue. I do not believe that it is really an
apple problem. I think gfortran is doing something that apple considers
invalid.
The "-Wl,-read_only_relocs suppress" argument only works if you compile in 32
bit (with "-m32") otherwise it is not a valid argument:
$ gfortran-7 -shared -fPIC "-Wl,-read_only_relocs suppress" foo.f90
ld: unknown option: -read_only_relocs suppress
collect2: error: ld returned 1 exit status
Ryan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-04-16 21:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-16 16:18 Darwin linker error "illegal text-relocation" with -shared Ryan S. Elliott
2018-04-16 18:20 ` Thomas Koenig
2018-04-16 19:35 ` Ryan S. Elliott
2018-04-16 19:46 ` Thomas Koenig
2018-04-16 19:51 ` Ryan S. Elliott
2018-04-16 20:14 ` Steve Kargl
2018-04-16 21:09 ` Ryan S. Elliott
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).