M
M
Mercury132020-02-11 16:06:41
Qt
Mercury13, 2020-02-11 16:06:41

Qt + MinGW + LTO + LLD: how to make them work together?

The glitch is reproduced like this.
1. Install MSYS (MinGW and LLD), Qt (any version) under Windows.
2. Build your own kit from the compiler from MSYS and any version of Qt from the distribution.
3. Build an empty Qt Widgets project . Add to it...

QMAKE_CXXFLAGS += -flto
QMAKE_LFLAGS += -flto -fuse-ld=lld

When linking, it does not find the qMain function.

Okay, let's write this...
# Special LTO features for main.cpp
CONFIG(release, debug|release) {
        win32|win64 {
            FAT_SOURCES = main1.cpp

            fat.name = FAT_SOURCES
            fat.dependency_type = TYPE_C
            fat.variable_out = OBJECTS
            fat.input = FAT_SOURCES
            fat.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}$${first(QMAKE_EXT_OBJ)}
            fat.commands = $${QMAKE_CXX} $(CXXFLAGS) $(INCPATH) -c ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT} -ffat-lto-objects

            QMAKE_EXTRA_COMPILERS += fat
    }
}

(in the main1.cpp file, a simple include main.cpp)

Then it does not find the functions that are called from this main.cpp.

If you bang the whole project with -ffat-lto-objects, everything works ... except for that very LTO. The size of the compiled EXE shows that no one has optimized it.

__attribute__ ((used))gives nothing.

What to do? How to tell this very LTO that the “entry point” is qMain, and not main?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2020-02-11
@Mercury13

Unfortunately, I'm asking for the impossible. And this is due to the optimization architecture when linking GCC. The fact is that LD itself calls the optimizer, and it's a damn pity. After all, LLVM has a different virtual machine device that does optimization when linking.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question