https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92404

            Bug ID: 92404
           Summary: GCC4.1.2 using “-fPIE -Wl,-pie”
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dno.gcc at gmail dot com
  Target Milestone: ---

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?

Reply via email to