bug-binutils
[Top][All Lists]
Advanced

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

[Bug ld/27122] New: ld -r does not complain about LTO/non-LTO mix and si


From: slyfox at inbox dot ru
Subject: [Bug ld/27122] New: ld -r does not complain about LTO/non-LTO mix and silently produces invalid object files.
Date: Mon, 28 Dec 2020 13:40:20 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=27122

            Bug ID: 27122
           Summary: ld -r does not complain about LTO/non-LTO mix and
                    silently produces invalid object files.
           Product: binutils
           Version: 2.36 (HEAD)
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: slyfox at inbox dot ru
                CC: hjl.tools at gmail dot com
  Target Milestone: ---

Re-discovered in https://github.com/gentoo-haskell/gentoo-haskell/issues/1110.

PR12291 tracks support for mixed LTO/non-LTO objects. While it's not
implemented should ld complain about data loss when partial linking is used?
gcc's man page suggest it should but I'm not sure if it's ld's problem or gcc's
linker plugin problem.

gcc's manpage says:

```
       -flinker-output=type

           During the incremental link (by -r) the linker plugin defaults to
rel. With current interfaces to GNU Binutils it is however not possible to
incrementally link LTO objects and
           non-LTO objects into a single mixed object file.  If any of object
files in incremental link cannot be used for link-time optimization, the linker
plugin issues a warning and
           uses nolto-rel. To maintain whole program optimization, it is
recommended to link such objects into static library instead. Alternatively it
is possible to use H.J. Lu's
           binutils with support for mixed objects.
```

Example session (models upstream bug):

$ cat a.c
  void a(void) {}

$ cat b.c
  void a(void); /* from non-lto */
  int main(void) { a(); }

$ LANG=C bash -x ./mk.bash
+ x86_64-pc-linux-gnu-gcc-11.0.0 -c a.c
+ x86_64-pc-linux-gnu-gcc-11.0.0 -flto -c b.c
+ x86_64-pc-linux-gnu-gcc-11.0.0 a.o b.o -o o1
+ x86_64-pc-linux-gnu-ld -r a.o b.o -o o.o
+ x86_64-pc-linux-gnu-gcc-11.0.0 -flto o.o -o o2
/usr/lib/gcc/x86_64-pc-linux-gnu/11.0.0/../../../../x86_64-pc-linux-gnu/bin/ld:
/tmp/ccHmkp4T.ltrans0.ltrans.o: in function `main':
<artificial>:(.text+0x5): undefined reference to `a'
collect2: error: ld returned 1 exit status

Note: `x86_64-pc-linux-gnu-ld -r a.o b.o -o o.o` issued no warnings.

Thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]