GCC4.1.2 using “-fPIE -Wl,-pie”

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

 



Lets say I have an project which has an library in which I have one
function which returns a single value, for example:
unsigned long cFun1()
{
    return 1000;
}
Then, I have an mock of the function in the main.cpp, with the same
name, and the difference is that it returns some other result, for
example:
unsigned long cFun1()
{
    return 45;
}
So, in the main, I am calling the simple function like this:
int main()
{
    long retVal = cFun1();

    return 0;
}
When I use gcc as:
Solution1
cc1: -fvisibility=hidden -fno-builtin -ggdb -nostdinc %(cc1_cpu)
*link_command:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ ld -shared
-z defs --exclude-libs ALL %l %X %{o} %{A} %{d} %{e*} %{m} %{N} %{n}
%{r}\ %{s} %{t} %{u*} %{x} %{z} %{Z} \ %{L*} %(link_libgcc) %o \
%{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}

the function which is in the library is called, which is not something
that I want. What I want to do is to call the mocked function which is
in the main.cpp. For that I am adding following flags: -fPIE -Wl,-pie
Compiling the application with this flags results in calling the
mocked function which is in the main.cpp and which returns 45.

My question is, what are the differences between above mentioned
solution and this one:
Solution2
cc1: -falign-functions=4 -fno-jump-tables -fno-builtin -nostdinc
%(cc1_cpu) *link_command:%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\
ld -q -pie %l %X %{o} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\ %{s} %{t}
%{u*} %{x} %{z} %{Z} \ %{L*} %(link_libgcc) %o \
%{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}

Is there a possibility to use Solution1 without using pie flags, and
get the mocked functions call?



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux