public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC4.1.2 using “-fPIE -Wl,-pie”
@ 2019-11-07  7:26 dno gcc
  0 siblings, 0 replies; only message in thread
From: dno gcc @ 2019-11-07  7:26 UTC (permalink / raw)
  To: gcc-help

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?

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-11-07  7:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-07  7:26 GCC4.1.2 using “-fPIE -Wl,-pie” dno gcc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).