help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFLAGS/LDFLAGS for PIE vs PIC?


From: Bryan Ischo
Subject: Re: CFLAGS/LDFLAGS for PIE vs PIC?
Date: Mon, 02 Apr 2012 00:08:55 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111108 Thunderbird/8.0

On 04/01/12 23:10, John Calcote wrote:

Perhaps I'm showing my ignorance here, but I find it difficult to understand
why any source file should ever be compiled without -fPIC. Are we really
worried about a few bytes of storage or memory in this day and age? This
flag has been the crux of all logistical problems I've ever dealt with when
building linux objects.

For example, there are times when I need to build objects that will be
linked statically into a program AND statically into a shared library. Do I
build two static libraries: one called libutil_static.a and libutil.a? That
seems silly and wasteful. Rather, I've found it simpler in this case to just
build all these "util" source files with -fPIC and archive them all into one
libutil.a that can be linked both into my programs and into my shared
libraries.

If anyone has any input, I'd love to hear good reasons for not just
disregarding non-pic code these days.

Always building objects with PIC flags is a fine choice too if that's the way you want to go. I have experienced embedded environments where the difference in code size and performance of unnecessary PIC code was an issue, but that is a very specific scenario and not relevant to 99.9% of the cases where these choices are made.

I personally just like to solve problems in a way that feels the "most correct". Somehow letting little things slide gives me a sense that an inevitable creep towards poor quality will result. It's why I always build correct functional dependency rules in my makefiles, why I don't ever use recursive make, and why I care about compiler warnings that wouldn't otherwise stop the compilation unless I pass a -Werr flag (which I always do). It gives me a sense of completeness to know that only the code that needs to be PIC in my program or libraries is PIC.

But as far as I know, this factor aside, and excepting also those very rare cases where the size or performance penalties of PIC matter, there is no reason otherwise to not always compile everything PIC, in which case making a Makefile, either manually written or generated using GNU autoconf, is an easier task.

Bryan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]