Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

ICC generates position-dependent code for a library?!

vectorizor
New Contributor I
775 Views
Hi,

I'm trying to compile a Mac version of our lib for a customer that wants to include it in a Photoshop plugin, and he is having trouble linking our lib into his app. More detailed info: His plugin is built using gcc and the 10.4 Mac OS base SDK. My lib is a static one, compiled with the Intel compiler 10.1 and the base SDK is also set as 10.4. While its fine for me, my customer cannot manage to link with my lib. The problem is the following:

absolute addressing (perhaps -mdynamic-no-pic) used in _Cholesky from /mylib.a(Cholesky.o) not allowed in slidable image. Use '-read_only_relocs suppress' to enable text relocs

I really do not understand why ICC is generating position-dependent code for a library?! Any idea on how to fix this? Or a way to work around it?

A
0 Kudos
10 Replies
TimP
Honored Contributor III
775 Views
icc should observe the same options as gcc for generating pic code. The default (non-pic) would be expected to be the same as gcc. Reasons for the default likewise would be same as gcc, including performance of globally visible entry points.
0 Kudos
dpeterc
Beginner
775 Views
Position independent code is slower, so it is normal that it is disabled by default.
Use -fPIC to generate position independent code. This is a must for a shared library (.so), but optional for static one (.a)
You may also wish to check this thread:
http://stackoverflow.com/questions/813980/why-isnt-all-code-compiled-position-independent
0 Kudos
vectorizor
New Contributor I
775 Views
Quoting - dpeterc
Position independent code is slower, so it is normal that it is disabled by default.
Use -fPIC to generate position independent code. This is a must for a shared library (.so), but optional for static one (.a)
You may also wish to check this thread:
http://stackoverflow.com/questions/813980/why-isnt-all-code-compiled-position-independent

I'm using Xcode to compile. I just looked at the compilation output on the command-line, and there does not seem to be any options related to position (in)dependent code. More specifically, a search for pic or fpic returns nothing.

I would expect Xcode or ICC to handle this, after I'm requesting them to build a static lib. Shouldn't -fPIC be there by default?

Thanks,

A


0 Kudos
dpeterc
Beginner
775 Views
Quoting - vectorizor

I'm using Xcode to compile. I just looked at the compilation output on the command-line, and there does not seem to be any options related to position (in)dependent code. More specifically, a search for pic or fpic returns nothing.

I would expect Xcode or ICC to handle this, after I'm requesting them to build a static lib. Shouldn't -fPIC be there by default?


icc --help
will show you, among many other things:
-fpic, -fPIC
generate position independent code (-fno-pic/-fno-PIC is DEFAULT)


The way I am used to program, the programer needs to know and decide compiler options.

I don't have a mac, but looking at the xcode documentation
http://developer.apple.com/tools/xcode/xcodebuildsettings.html
it looks like a fancy gui make.
I think you are being seduced by shiny buttons into thinking, that xcode will do more for you than it can ;-)
0 Kudos
TimP
Honored Contributor III
775 Views
Quoting - dpeterc

icc --help
will show you, among many other things:
-fpic, -fPIC
generate position independent code (-fno-pic/-fno-PIC is DEFAULT)

I think you are being seduced by shiny buttons into thinking, that xcode will do more for you than it can ;-)
Such as guess your desires? As mentioned earlier, static libraries typically contain no-pic objects, so the additional option is needed to change that selection.
0 Kudos
vectorizor
New Contributor I
775 Views
Quoting - dpeterc

icc --help
will show you, among many other things:
-fpic, -fPIC
generate position independent code (-fno-pic/-fno-PIC is DEFAULT)


The way I am used to program, the programer needs to know and decide compiler options.

I don't have a mac, but looking at the xcode documentation
http://developer.apple.com/tools/xcode/xcodebuildsettings.html
it looks like a fancy gui make.
I think you are being seduced by shiny buttons into thinking, that xcode will do more for you than it can ;-)

Thanks for the answer. I did have a good look at all compiler options available, but I cannot find anything that would help solve my issue. The -fPIC sounds interesting, but it does not appear on 10.1. Any other ideas?

And for the comment about xcode doing more for me than it can, I requested to generate a static library. If it is too much to ask of a IDE/compiler to generate by default pic code for a shared library, then my bad.

Thanks again

A




0 Kudos
vectorizor
New Contributor I
775 Views
Quoting - tim18
Such as guess your desires? As mentioned earlier, static libraries typically contain no-pic objects, so the additional option is needed to change that selection.

Thanks for the answer Tim. One question though: why would a static lib contain no-pic objects? It is meant to be shared, or am I being extremely thick here?

A
0 Kudos
TimP
Honored Contributor III
775 Views
Quoting - vectorizor

Thanks for the answer Tim. One question though: why would a static lib contain no-pic objects? It is meant to be shared, or am I being extremely thick here?

A
The tools have no idea at the time you create a static library that you may wish to use it to make a shared library. So, it's up to you to specify -pic if you require it. As several of us have said, use of a static library in static linking is entirely normal, probably the most common usage.
0 Kudos
dpeterc
Beginner
775 Views

Quoting - vectorizor
Thanks for the answer. I did have a good look at all compiler options available, but I cannot find anything that would help solve my issue. The -fPIC sounds interesting, but it does not appear on 10.1. Any other ideas?
It does appear that you are right and that -fPIC is not available on icc 10.1 on OSX
http://www.nacad.ufrj.br/intel/cc/main_cls/mergedProjects/copts_cls/common_options/option_fpic.htm
I would assume that in that case, -fPIC behavior would be the default, there must be some technical reasons for it.
I think you need advice from someone with actual OSX experience, not me ;-(


0 Kudos
Om_S_Intel
Employee
775 Views

The -fpic compiler option is available in icc 10.1. You may use it for generating position independent code.

$ icc -c -fpic mysource.cpp
$ icc -V
Intel C Compiler for applications running on IA-32, Version 10.1 Build 20080312 Package ID: m_cc_p_10.1.014
Copyright (C) 1985-2008 Intel Corporation. All rights reserved.
0 Kudos
Reply