Bug 832545

Summary: libz.a not being compiled with -fPIC on x86_64
Product: [Fedora] Fedora Reporter: Orion Poplawski <orion>
Component: zlibAssignee: Peter Schiffer <pschiffe>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 16CC: aschorr, pertusus, pschiffe
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-08-22 20:59:47 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Orion Poplawski 2012-06-15 17:31:27 UTC
Description of problem:

libz.a not being compiled with -fPIC on x86_64.  Leads to:

/bin/ld: /usr/lib/libz.a(compress.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC

Might need to specify -DPIC too, not sure about the zlib code.

Version-Release number of selected component (if applicable):
zlib-static-1.2.5-6

Comment 1 Peter Schiffer 2012-07-30 12:41:03 UTC
Hello,

could you test this build please?
http://koji.fedoraproject.org/koji/taskinfo?taskID=4342268

Thanks,

peter

Comment 2 Orion Poplawski 2012-08-01 22:38:32 UTC
For the life of me, I cannot remember what I was compiling at the time to generate this error, but the build logs look good.

Comment 3 Peter Schiffer 2012-08-02 13:17:36 UTC
Thanks for check.

Fixed in:
zlib-1.2.7-5.fc18
http://koji.fedoraproject.org/koji/buildinfo?buildID=345453

Comment 4 Fedora Update System 2012-08-02 13:35:34 UTC
zlib-1.2.5-7.fc17 has been submitted as an update for Fedora 17.
https://admin.fedoraproject.org/updates/zlib-1.2.5-7.fc17

Comment 5 Fedora Update System 2012-08-02 13:36:35 UTC
zlib-1.2.5-7.fc16 has been submitted as an update for Fedora 16.
https://admin.fedoraproject.org/updates/zlib-1.2.5-7.fc16

Comment 6 Fedora Update System 2012-08-03 11:24:45 UTC
Package zlib-1.2.5-7.fc17:
* should fix your issue,
* was pushed to the Fedora 17 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing zlib-1.2.5-7.fc17'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2012-11432/zlib-1.2.5-7.fc17
then log in and leave karma (feedback).

Comment 7 Fedora Update System 2012-08-22 20:59:47 UTC
zlib-1.2.5-7.fc16 has been pushed to the Fedora 16 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 8 Fedora Update System 2012-08-22 21:03:02 UTC
zlib-1.2.5-7.fc17 has been pushed to the Fedora 17 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 9 Andrew J. Schorr 2012-08-27 14:48:03 UTC
Hi,

I am confused by this patch.  Why is it desirable to compile libz.a with -fPIC?
It is a static library, and those are typically compiled without -fPIC.  For
shared library linkage, libz.so is supplied.

Thanks,
Andy

Comment 10 Orion Poplawski 2012-08-27 15:29:58 UTC
See the original report.  On x86_64 static archives are required to be compiled with -fPIC as well.

Comment 11 Andrew J. Schorr 2012-08-27 15:34:15 UTC
Can you please point me to the relevant manual that explains it?  I have never
before heard of a requirement that static libraries need to be compiled with
-fPIC.  I thought the whole point of -fPIC was to allow the dynamic relocation
needed for shared libraries.  With static libraries, symbols are resolved at
link time, so -fPIC should not be needed.  It would be helpful for me to learn
if I am wrong about this.

Note: the original bug report supplied an error message, but it did not include
any context showing what generated the error.  So it is impossible to judge
what went wrong.

Thanks,
Andrew

Comment 12 Andrew J. Schorr 2012-08-28 12:34:54 UTC
Hi,

Can you please re-open this bug and revert the patch?  From the gcc manual:

http://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Code-Gen-Options.html#Code-Gen-Options

-fpic
    Generate position-independent code (PIC) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table (GOT). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that -fpic does not work; in that case, recompile with -fPIC instead. (These maximums are 8k on the SPARC and 32k on the m68k and RS/6000. The 386 has no such limit.)

    Position-independent code requires special support, and therefore works only on certain machines. For the 386, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent.

    When this flag is set, the macros __pic__ and __PIC__ are defined to 1.
-fPIC
    If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table. This option makes a difference on the m68k, PowerPC and SPARC. 


As it clearly says, these options are for making shared libraries, not static libraries.

Do I need to open a new bug to get this fixed?

Thanks,
Andy

Comment 13 Peter Schiffer 2012-08-28 13:49:02 UTC
Hi Andrew,

it looks like you are right, -fPIC option is not desirable for static libraries or executables. However, some packages tries to build shared libraries using statically built archives and then they can require -fPIC on static libraries. In this case, it is OK to build static library with -fPIC, but only on x86_64. On other architectures it's not needed and can cause performance impact at execution time. For more information see [1].

So.. for Fedora 16 and 17 I would keep it as it is now, I don't think this is worth an update.

And for rawhide and Fedora 18 I am thinking about enabling -fPIC for static library for x86_64 arch only, for compatibility reasons.. What do you think about this solution?

Thanks,

peter


[1] http://www.gentoo.org/proj/en/base/amd64/howtos/index.xml?part=1&chap=3

Comment 14 Andrew J. Schorr 2012-08-28 13:56:18 UTC
Hi,

I'm not sure I fully understand.  The only reason I can see for compiling a
static library with -fpic (or -fPIC) is if a developer wants to build his own
shared library that incorporates the libz.a contents.  However, I don't think
that is a good solution.  In such a case, the new shared library should simply
link in libz.so instead of trying to duplicate the libz code inside the new shared
library.

I may be missing something, but I think the standard approach is NOT to use
-fpic for a static library.  I don't see why libz.a should be different than
all the other static libraries on the system.  What am I missing?

Thanks,
Andrew

Comment 15 Peter Schiffer 2012-08-28 14:42:31 UTC
Well, as I said, you are right. The standard approach is not to use -fPIC for static library. But as you can see, (like this bug report), there are packages that fail to build if libz.a is compiled without -fPIC on x86_64. I understand that problem is in that package and not in libz.a, but this can happen not only to developers, but also to regular users who just need to compile some downloaded software. Also, it looks like there is no drawback for enabling -fPIC on static libraries only on x86_64 arch, so why wouldn't we help them?

peter

Comment 16 Andrew J. Schorr 2012-08-28 14:47:00 UTC
Hi Peter,

I'm not trying to be a hardass, but this is just wrong.  Would you compile
glibc with -fPIC if somebody requested it in a bug report without offering
any explanation of why?  This bug report does not even identify the code
that won't build.  The bug is in the other project, not in libz.a.  The bug
should be fixed in the proper place.  Static libraries should not be
compiled with -fPIC.

Those are my 2 cents.  I am baffled by the decision to compile a static library
with -fPIC.  It's just totally random.  Where's the list of packages that
require this?

Regards,
Andy

Comment 17 Peter Schiffer 2012-08-29 11:55:39 UTC
Andrew,

OK then. I was thinking about this and I'll revert this change in Fedora 18 and rawhide, so libz.a will be compiled without -fPIC.

peter

Comment 18 Andrew J. Schorr 2012-08-29 11:58:07 UTC
Thank you.

Comment 19 Fedora Update System 2012-08-29 13:30:36 UTC
zlib-1.2.7-8.fc18 has been submitted as an update for Fedora 18.
https://admin.fedoraproject.org/updates/zlib-1.2.7-8.fc18

Comment 20 Peter Schiffer 2012-08-29 13:36:21 UTC
rawhide build:
zlib-1.2.7-8.fc19
http://koji.fedoraproject.org/koji/buildinfo?buildID=351163

Comment 21 Fedora Update System 2012-09-17 23:17:39 UTC
zlib-1.2.7-8.fc18 has been pushed to the Fedora 18 stable repository.  If problems still persist, please make note of it in this bug report.