public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* confused by -mfentry and -mrecord-mcount linker errors
@ 2022-01-10  5:03 Christopher Harvey
  0 siblings, 0 replies; only message in thread
From: Christopher Harvey @ 2022-01-10  5:03 UTC (permalink / raw)
  To: gcc-help

Hi,

I'll try to keep this short. See the end of this email for the question. The beginning is a minimal example and the linker errros:

bash prompt>> cat a.cpp 
#include "a.hpp"
#include <ostream>

std::ostream& operator<<(std::ostream &os, const Info &info) {
    using namespace std;
    os<<hex<<info.a<<dec;
    return os;
}

bash prompt>> cat a.hpp
#pragma once

#include <ostream>

struct Info {
    int a;
};

std::ostream& operator<<(std::ostream &os, const Info &info);

bash prompt>> cat main.cpp 
#include <iostream>
#include "a.hpp"

using namespace std;

int main() {
    cout<<hex<<endl;
}

bash prompt>> g++ -pg -mrecord-mcount -mno-nop-mcount -mfentry -minstrument-return=nop5 -mrecord-return a.cpp -c -o a.o

bash prompt>> g++ -pg -mrecord-mcount -mno-nop-mcount -mfentry -rdynamic -minstrument-return=nop5 -mrecord-return main.cpp a.o
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccSjK9Ef.o: warning: relocation in read-only section `__return_loc'
`.text._ZStanSt13_Ios_FmtflagsS_' referenced in section `__mcount_loc' of a.o: defined in discarded section `.text._ZStanSt13_Ios_FmtflagsS_[_ZStanSt13_Ios_FmtflagsS_]' of a.o
`.text._ZStorSt13_Ios_FmtflagsS_' referenced in section `__mcount_loc' of a.o: defined in discarded section `.text._ZStorSt13_Ios_FmtflagsS_[_ZStorSt13_Ios_FmtflagsS_]' of a.o
`.text._ZStcoSt13_Ios_Fmtflags' referenced in section `__mcount_loc' of a.o: defined in discarded section `.text._ZStcoSt13_Ios_Fmtflags[_ZStcoSt13_Ios_Fmtflags]' of a.o
`.text._ZStoRRSt13_Ios_FmtflagsS_' referenced in section `__mcount_loc' of a.o: defined in discarded section `.text._ZStoRRSt13_Ios_FmtflagsS_[_ZStoRRSt13_Ios_FmtflagsS_]' of a.o
`.text._ZStaNRSt13_Ios_FmtflagsS_' referenced in section `__mcount_loc' of a.o: defined in discarded section `.text._ZStaNRSt13_Ios_FmtflagsS_[_ZStaNRSt13_Ios_FmtflagsS_]' of a.o
`.text._ZNSt8ios_base4setfESt13_Ios_FmtflagsS0_' referenced in section `__mcount_loc' of a.o: defined in discarded section `.text._ZNSt8ios_base4setfESt13_Ios_FmtflagsS0_[_ZNSt8ios_base4setfESt13_Ios_FmtflagsS0_]' of a.o
`.text._ZSt3hexRSt8ios_base' referenced in section `__mcount_loc' of a.o: defined in discarded section `.text._ZSt3hexRSt8ios_base[_ZSt3hexRSt8ios_base]' of a.o
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

Here is the kicker: Passing -O3 to the linker creates an executable (with some warnings that I also don't really understand)

bash prompt>> g++ -O3 -pg -mrecord-mcount -mno-nop-mcount -mfentry -rdynamic -minstrument-return=nop5 -mrecord-return main.cpp a.o
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccK8XY8Y.o: warning: relocation in read-only section `__return_loc'
/usr/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: warning: creating DT_TEXTREL in a PIE


What am I doing wrong and what do the linker warnings and errors mean? My end goal is just to add patchable bytes at each function and ret instruction. When the executable compiles it looks right. The __mcount_loc and corresponding return location sections would also be really nice to have.

Thanks!

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

only message in thread, other threads:[~2022-01-10  5:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10  5:03 confused by -mfentry and -mrecord-mcount linker errors Christopher Harvey

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).