Discussion:
[developer] Function call from the .init section
Gary Mills via illumos-developer
2014-10-13 18:34:42 UTC
Permalink
I had something peculiar come up while I was attempting to build
illumos with a current version of openssl included. During linking of
the libcrypto shared library, I got this error:

Text relocation remains referenced
against symbol offset in file
OPENSSL_cpuid_setup 0x1 pics/x86cpuid.o
ld: fatal: relocations remain against allocatable but non-writable sections
Current working directory .../usr/src/lib/openssl/libcrypto/i386

That function is in another module: cryptlib.o . Links to that
function from other modules were resolved. It's only the one from
x86cpuid.o that was left out. That object file was created from the
x86cpuid.s assembler file, which reads like this:

.section .init
call OPENSSL_cpuid_setup

Is the function call somehow special because it's in the .init
section? When I replace `-Bdirect' with `-Bsymbolic' on the link
line, it completes successfully. Although it works, I'm assuming
that's not an ideal solution. Is there a better one?
--
-Gary Mills- -refurb- -Winnipeg, Manitoba, Canada-


-------------------------------------------
illumos-developer
Archives: https://www.listbox.com/member/archive/182179/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182179/21175072-86d49504
Modify Your Subscription: https://www.listbox.com/member/?member_id=21175072&id_secret=21175072-abdf7b7e
Powered by Listbox: http://www.listbox.com
Richard Lowe via illumos-developer
2014-10-13 19:11:08 UTC
Permalink
It's not .init, the ASM looks non-PIC. If you called it via the PLT
you should be fine.

-B symbolic is working because it's binding during the link-edit, and
no relocation's left at all. I don't think that's really what you'd
want over all.


-------------------------------------------
illumos-developer
Archives: https://www.listbox.com/member/archive/182179/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182179/21175072-86d49504
Modify Your Subscription: https://www.listbox.com/member/?member_id=21175072&id_secret=21175072-abdf7b7e
Powered by Listbox: http://www.listbox.com
Gary Mills via illumos-developer
2014-10-13 22:29:29 UTC
Permalink
Post by Richard Lowe via illumos-developer
It's not .init, the ASM looks non-PIC. If you called it via the PLT
you should be fine.
That's the usual problem, one that I've encountered before. I didn't
write the assembler file. It's generated by a perl script that's part
of the openssl distribution. It seems to be the only one that can't
produce PIC code. That's a puzzle.
Post by Richard Lowe via illumos-developer
-B symbolic is working because it's binding during the link-edit, and
no relocation's left at all. I don't think that's really what you'd
want over all.
Thanks. That explains why it worked. I'll look for a proper
solution.
--
-Gary Mills- -refurb- -Winnipeg, Manitoba, Canada-


-------------------------------------------
illumos-developer
Archives: https://www.listbox.com/member/archive/182179/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182179/21175072-86d49504
Modify Your Subscription: https://www.listbox.com/member/?member_id=21175072&id_secret=21175072-abdf7b7e
Powered by Listbox: http://www.listbox.com
Alexander Pyhalov via illumos-developer
2014-10-14 03:40:01 UTC
Permalink
Post by Gary Mills via illumos-developer
I had something peculiar come up while I was attempting to build
illumos with a current version of openssl included. During linking of
Text relocation remains referenced
against symbol offset in file
OPENSSL_cpuid_setup 0x1 pics/x86cpuid.o
ld: fatal: relocations remain against allocatable but non-writable sections
Current working directory .../usr/src/lib/openssl/libcrypto/i386
That function is in another module: cryptlib.o . Links to that
function from other modules were resolved. It's only the one from
x86cpuid.o that was left out. That object file was created from the
.section .init
call OPENSSL_cpuid_setup
Is the function call somehow special because it's in the .init
section? When I replace `-Bdirect' with `-Bsymbolic' on the link
line, it completes successfully. Although it works, I'm assuming
that's not an ideal solution. Is there a better one?
Hello. This works here for in-gate openssl version.
$ file i386/pics/x86cpuid.o
i386/pics/x86cpuid.o: ELF 32-bit LSB relocatable 80386 Version 1


diff -u
/home/alp/srcs/oi-userland/components/openssl/openssl-1.0.1/openssl-1.0.1i/crypto/x86cpuid.pl
pl/x86cpuid.pl
---
/home/alp/srcs/oi-userland/components/openssl/openssl-1.0.1/openssl-1.0.1i/crypto/x86cpuid.pl
2014-08-07 01:10:56.000000000 +0400
+++ pl/x86cpuid.pl 2014-06-19 12:29:38.405743624 +0400
@@ -1,7 +1,7 @@
#!/usr/bin/env perl

$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
-push(@INC, "${dir}perlasm", "perlasm");
+push(@INC, "${dir}", "perlasm");
require "x86asm.pl";

&asm_init($ARGV[0],"x86cpuid");
@@ -353,6 +353,11 @@
&ret ();
&function_end_B("OPENSSL_ia32_rdrand");

+&initseg("illumos_locking_setup");
&initseg("OPENSSL_cpuid_setup");

+&hidden("illumos_locking_setup");
+&hidden("OPENSSL_cpuid_setup");
+&hidden("OPENSSL_ia32cap_P");
+
&asm_finish();

Perhaps, you miss addition of &hidden directives?
---
System Administrator of Southern Federal University Computer Center





-------------------------------------------
illumos-developer
Archives: https://www.listbox.com/member/archive/182179/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182179/21175072-86d49504
Modify Your Subscription: https://www.listbox.com/member/?member_id=21175072&id_secret=21175072-abdf7b7e
Powered by Listbox: http://www.listbox.com
Gary Mills via illumos-developer
2014-10-14 15:09:32 UTC
Permalink
Post by Alexander Pyhalov via illumos-developer
Hello. This works here for in-gate openssl version.
$ file i386/pics/x86cpuid.o
i386/pics/x86cpuid.o: ELF 32-bit LSB relocatable 80386 Version 1
Mine too:

$ file i386/pics/x86cpuid.o
i386/pics/x86cpuid.o: ELF 32-bit LSB relocatable 80386 Version 1

It seems that the file command is not reliable, at least when the
object file is built from assembler source. I noticed this earlier
with object files that were non-PIC through an oversight.
Post by Alexander Pyhalov via illumos-developer
diff -u /home/alp/srcs/oi-userland/components/openssl/openssl-1.0.1/openssl-1.0.1i/crypto/x86cpuid.pl
[...]
Post by Alexander Pyhalov via illumos-developer
@@ -353,6 +353,11 @@
&ret ();
&function_end_B("OPENSSL_ia32_rdrand");
+&initseg("illumos_locking_setup");
&initseg("OPENSSL_cpuid_setup");
+&hidden("illumos_locking_setup");
+&hidden("OPENSSL_cpuid_setup");
+&hidden("OPENSSL_ia32cap_P");
+
&asm_finish();
This must be your own patch; it's not the same as the Oracle patch.
Post by Alexander Pyhalov via illumos-developer
Perhaps, you miss addition of &hidden directives?
Yes, those are missing. I've been looking at the 64-bit equivalent,
which doesn't have that problem. The 64-bit library builds normally,
with direct binding. The perl script that generates that assembler
file has this:

print<<___;
+ .extern OPENSSL_cpuid_setup
+ .hidden OPENSSL_cpuid_setup
.section .init
+ call OPENSSL_cpuid_setup

That symbol seems to be marked both hidden and external. I wonder
if that's what makes the 64-bit library build correctly.
--
-Gary Mills- -refurb- -Winnipeg, Manitoba, Canada-


-------------------------------------------
illumos-developer
Archives: https://www.listbox.com/member/archive/182179/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182179/21175072-86d49504
Modify Your Subscription: https://www.listbox.com/member/?member_id=21175072&id_secret=21175072-abdf7b7e
Powered by Listbox: http://www.listbox.com
Richard Lowe via illumos-developer
2014-10-14 15:15:53 UTC
Permalink
It's hard to tell from the context if either of you are actually
making this mistake, but I'm going to correct it anyway just in case:

"relocatable object" doesn't mean PIC, it just means ET_REL.


-------------------------------------------
illumos-developer
Archives: https://www.listbox.com/member/archive/182179/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182179/21175072-86d49504
Modify Your Subscription: https://www.listbox.com/member/?member_id=21175072&id_secret=21175072-abdf7b7e
Powered by Listbox: http://www.listbox.com
Gary Mills via illumos-developer
2014-10-14 16:05:24 UTC
Permalink
Post by Richard Lowe via illumos-developer
It's hard to tell from the context if either of you are actually
"relocatable object" doesn't mean PIC, it just means ET_REL.
I, for one, am making that mistake. I see that elfdump on that
troublesome file says:

e_type: ET_REL

It also says that on a file that is PIC. Is there anything in an
object file to identify it as PIC?
--
-Gary Mills- -refurb- -Winnipeg, Manitoba, Canada-


-------------------------------------------
illumos-developer
Archives: https://www.listbox.com/member/archive/182179/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182179/21175072-86d49504
Modify Your Subscription: https://www.listbox.com/member/?member_id=21175072&id_secret=21175072-abdf7b7e
Powered by Listbox: http://www.listbox.com
Gary Mills via illumos-developer
2014-10-22 17:41:49 UTC
Permalink
Post by Alexander Pyhalov via illumos-developer
Post by Gary Mills via illumos-developer
Text relocation remains referenced
against symbol offset in file
OPENSSL_cpuid_setup 0x1 pics/x86cpuid.o
ld: fatal: relocations remain against allocatable but
non-writable sections
Current working directory .../usr/src/lib/openssl/libcrypto/i386
Hello. This works here for in-gate openssl version.
[...]
Post by Alexander Pyhalov via illumos-developer
+&initseg("illumos_locking_setup");
&initseg("OPENSSL_cpuid_setup");
+&hidden("illumos_locking_setup");
+&hidden("OPENSSL_cpuid_setup");
+&hidden("OPENSSL_ia32cap_P");
[...]
Post by Alexander Pyhalov via illumos-developer
Perhaps, you miss addition of &hidden directives?
Yes, that seems to be it. I added a .hidden directive to
perlasm/x86gas.pl . Now I can build the library with direct linking.
(There was no &hidden function, but perhaps I'm using an older version
of openssl.)
--
-Gary Mills- -refurb- -Winnipeg, Manitoba, Canada-


-------------------------------------------
illumos-developer
Archives: https://www.listbox.com/member/archive/182179/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182179/21175072-86d49504
Modify Your Subscription: https://www.listbox.com/member/?member_id=21175072&id_secret=21175072-abdf7b7e
Powered by Listbox: http://www.listbox.com
Continue reading on narkive:
Loading...