Bug 24415 - - -Wl,--wrap= incompatible with -flto
Summary: - -Wl,--wrap= incompatible with -flto
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-03 14:33 UTC by dilyan.palauzov@aegee.org
Modified: 2024-02-29 01:08 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dilyan.palauzov@aegee.org 2019-04-03 14:33:54 UTC
This is t.c:
---------------
#include <stdio.h>
#include <unistd.h>

ssize_t __wrap_read(int fd, void *buffer, size_t count) {
  printf("%s\n", (char*)buffer);
  return fd + count; 
}


int main() {
  int i = read(1, "abc", 5);
  printf("%i\n", i);
}
---------------
I have gcc 8.3.1 20190331, clang 8.0.0, lld 8.0.0, ld.bfd 2.32.51.20190401 with the patch from https://sourceware.org/ml/binutils/2019-04/msg00011.html, and ld.gold (GNU Binutils 2.32.51.20190319) 1.16.

This works (compiles and links):

clang t.c -Wl,--wrap=read -O3 -fuse-ld=lld  -flto 
clang t.c -Wl,--wrap=read -O2 -fuse-ld=lld  -flto 
clang t.c -Wl,--wrap=read -O1 -fuse-ld=lld  -flto 
clang t.c -Wl,--wrap=read -O1 -fuse-ld=bfd  -flto 
clang t.c -Wl,--wrap=read -O2 -fuse-ld=bfd  -flto 
clang t.c -Wl,--wrap=read -O3 -fuse-ld=bfd  -flto 
clang t.c -Wl,--wrap=read -O3 -fuse-ld=gold -flto 
clang t.c -Wl,--wrap=read -O2 -fuse-ld=gold -flto 
clang t.c -Wl,--wrap=read -O1 -fuse-ld=gold -flto
gcc   t.c -Wl,--wrap=read -O3 -fuse-ld=bfd  -flto 
gcc   t.c -Wl,--wrap=read -O2 -fuse-ld=bfd  -flto 
gcc   t.c -Wl,--wrap=read -O1 -fuse-ld=bfd  -flto

This does not work (does not link):
gcc   t.c -Wl,--wrap=read -O1 -fuse-ld=gold  -flto
gcc   t.c -Wl,--wrap=read -O2 -fuse-ld=gold  -flto
gcc   t.c -Wl,--wrap=read -O3 -fuse-ld=gold  -flto

Bug for ld.bfd:
https://sourceware.org/bugzilla/show_bug.cgi?id=24406
Bug for GCC:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88643 (origin)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89930 (duplicate)