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

Reply via email to