confused by -mfentry and -mrecord-mcount linker errors

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

 



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!



[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