Questions tagged [link-time-optimization]

25 questions
10
votes
1 answer

Can LTO for gcc or clang optimize across C and C++ methods

If link-time optimization (LTO) is being used with gcc or clang, is it possible that code can be optimized across the C and C++ language boundary? For example, can a C function be inlined into a C++ caller?
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
9
votes
2 answers

INTERPROCEDURAL_OPTIMIZATION not set even if check_ipo_supported() works in CMake

I've the following project in CMake 3.14.0, that builds a project for Visual Studio 2017 64 bit generator (minimum version is 3.10.0 because other developer can have previous versions of CMake, but greater than 3.9.0): cmake_minimum_required…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
5
votes
0 answers

Why does link-time optimization cause a segmentation fault?

I am using Mingw-w64 v7 and g++ 10.2 on Windows built with the arguments --mode=gcc-10.2.0 --arch=x86_64 --buildroot=/c/mingw-builds/BuildRoot --update-sources --exceptions=seh --threads=posix --enable-languages=c++ --jobs=48 --rt-version=v7. I have…
5
votes
0 answers

With whole-program-optimization turned on, is inlining affected by where a method is implemented?

With whole-program (a.k.a link-time) optimization turned on, is inlining affected by where a method is implemented? Without whole-program-optimization turned on, methods which are publicly declared in a header but implemented in the matching cpp…
Danra
  • 9,546
  • 5
  • 59
  • 117
4
votes
3 answers

arm-none-eabi-g++ does not correctly handle weak alias with -flto

I am programming an STM32F413 microcontroller with SystemWorkbench 4 stm32. The Interrupt vectors are defined in an assembly startup file as weak aliases like follows: .weak TIM1_UP_TIM10_IRQHandler .thumb_set…
Alexander Daum
  • 741
  • 4
  • 14
4
votes
2 answers

Clang: How to check if LTO was performed

For gcc, this answer tells us how we can verify that Link-Time Optimization was performed. For clang, I cannot see any entries similar to .gnu.lto. More specifically, I have a binary where I am quite sure that LTO should have a significant benefit,…
mrks
  • 8,033
  • 1
  • 33
  • 62
3
votes
2 answers

Does forward declaration fully remove the need for any #including for pointer types?

Let's assume that we have a source file A.cpp where we forward declare a type ClassB, and then we keep using pointers to ClassB without ever #including file B.cpp (where ClassB is defined); And in B.cpp we forward declare ClassA and use a pointer to…
3
votes
3 answers

Is LTO allowed to remove unused global object if there is code in a different translation unit relying on side effects of its construction?

First, just to avoid XY problem: this issue comes from https://github.com/cnjinhao/nana/issues/445#issuecomment-502080177. The library code should probably not do such thing (reliance on construction of unused global object) but the question is more…
Xeverous
  • 973
  • 1
  • 12
  • 25
3
votes
0 answers

Undefined reference with link time optimization and --as-needed ld flag

I'm having some troubles compiling a large C++ project that uses link time optimization. After some digging I managed to produce an (almost) minimal working example that exhibits the same issue. Say that I have the following foo.cpp…
Steven
  • 209
  • 2
  • 10
3
votes
0 answers

Can you make a ".a" static lib containing both gcc and clang's IR code?

Both gcc and clang implement link-time optimization by allowing object files (.o) to not only contain the machine's target code, but also intermediate representations (GIMPLE or LLVM bitcode) used by the compilers themselves. Those object files can…
Mingye Wang
  • 1,107
  • 9
  • 32
3
votes
1 answer

Remove dead code before linking

In a project that consists of several statically linked object files, I am replacing one of them with a separate implementation. I would like to test my code even before I have implemented every symbol which the replaced object file provided, so I…
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
2
votes
1 answer

How to conditionally enable ltcg only if Qt was built with ltcg?

A qmake project is sometimes built using Qt that was compiled with ltcg. Since the Qt's ltcg build setting doesn't propagate automatically to that of the project that uses given Qt install, the MSVC linker wastes time and issues the following…
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
2
votes
1 answer

Using LTO with arm-none-eabi and newlib-nano

I'm working on an bare-metal embedded project for the STM32F103, and I'm using GNU ARM Embedded version 7-2017-q4-major toolchain. I'm currently compiling via GNU ARM Eclipse. I'm at a point where I need to start optimizing the project for speed,…
Timo
  • 739
  • 1
  • 6
  • 13
2
votes
1 answer

GCC -flto and inline keyword

My question is simple, does the keyword inline make a difference to the view of the link time optimization? With link time optimization I mean a GCC version which supports -flto(Link time optimization). For example: main.c #include "b.h" int main()…
Fredrik
  • 1,389
  • 1
  • 14
  • 32
1
vote
1 answer

ArmClang/ArmLink LTO removes object with __attribute__((used))

In a bootloader I have a version string that is not explicitly used, but must be present at a specific location in ROM for access by the application loaded by said bootloader. In a source file version.cpp I have: // Place version string at end of…
Clifford
  • 88,407
  • 13
  • 85
  • 165
1
2