From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by sourceware.org (Postfix) with ESMTPS id DEB0E3890435 for ; Mon, 10 Jan 2022 05:04:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DEB0E3890435 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 0B7F93200EF5 for ; Mon, 10 Jan 2022 00:04:34 -0500 (EST) Received: from imap44 ([10.202.2.94]) by compute5.internal (MEProxy); Mon, 10 Jan 2022 00:04:35 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrudegledgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdludehmdenucfjughrpefofg ggkfffhffvufgtsehttdertderredtnecuhfhrohhmpedfvehhrhhishhtohhphhgvrhcu jfgrrhhvvgihfdcuoegtfihhsegvmhhlrdgttgeqnecuggftrfgrthhtvghrnhepgeehie ekfeffvedufefhvdfghfetleejheevtdelteekheegffejkeffvddvkeeinecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheptgifhhesvghmlhdrtg gt X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 3F807FA0AA6; Mon, 10 Jan 2022 00:04:34 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4527-g032417b6d6-fm-20220109.002-g032417b6 Mime-Version: 1.0 Message-Id: <2a7ee82b-a593-4dc2-9c73-e48d4da846b2@www.fastmail.com> Date: Mon, 10 Jan 2022 00:03:25 -0500 From: "Christopher Harvey" To: gcc-help@gcc.gnu.org Subject: confused by -mfentry and -mrecord-mcount linker errors Content-Type: text/plain X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jan 2022 05:04:40 -0000 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 std::ostream& operator<<(std::ostream &os, const Info &info) { using namespace std; os<> cat a.hpp #pragma once #include struct Info { int a; }; std::ostream& operator<<(std::ostream &os, const Info &info); bash prompt>> cat main.cpp #include #include "a.hpp" using namespace std; int main() { cout<> 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!