>> Are you sure the linker does not perform this relaxation in your case? If so, >> that's an issue (missed optimization) in the linker. yes, after linking phase also I see reference memcpy from PLT.
The file I am building is created with -ffreestanding and -fnostdlib option; The memcpy function is provided in a different source file; The memcpy optimization is generated for a different source file. I am compiling all files with hidden visibility via the pragma declarative. After this I am linking the files using ld. After ld phase, I see that the final output binary is having references to PLT only in file which has structure pointer assignment. Nowhere else PLT reference is seen. >> (re)declaring memcpy with hidden visibility This method also does not work in my case. I am still seeing PLT relocations in my output file. In this case, if I am getting a memcpy@PLT reference then this bug should be similar to the one you pointer in earlier email, right? ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86695) - KGT - Keshav Gangadhar Tilak On Fri, Jul 27, 2018 at 2:24 PM Alexander Monakov <amona...@ispras.ru> wrote: > On Fri, 27 Jul 2018, keshav tilak wrote: > > This leads to GCC compiler issuing a call to `memcpy@PLT()' in function > bar1. > > > > I want to create a position independent executable from this source > > and run this on > > a secure environment which implements ASLR and the loader disallows any > binary > > which has PLT/GOT based relocations. > > The linker should be able to relax those nominally-PLT calls to direct > calls > since it emits a PIE and a local definition is available. Therefore the > loader > (the dynamic linker) should not get a GOT relocation for this call. > > Are you sure the linker does not perform this relaxation in your case? If > so, > that's an issue (missed optimization) in the linker. > > That said, the GCC should be able to emit direct calls as in some cases, > most > notably the 32-bit x86 ABI, it causes a size/speed penalty the linker would > not be able to clean up. > > What should work is (re)declaring memcpy with hidden visibility: > > __attribute__((visibility("hidden"))) > void *memcpy(void *, const void *, size_t); > > or via the pragma, but today this doesn't work. I've opened a GCC bugreport > for this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86695 > > Alexander >