premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.22k stars 620 forks source link

Generated link flags for debug config strip output #1238

Closed detly closed 5 years ago

detly commented 5 years ago

Using Premake 5.0.0-alpha13. Take this premake5.lua as an example:

workspace "test"
    configurations { "Debug", "Release" }

    project "testlib"
        kind "StaticLib"
        language "C"
        files { "lib.c" }

    project "test"
        kind "ConsoleApp"
        language "C"
        files { "main.c" }

Both premake5 gmake and premake5 gmake2 produce makefiles where the LDFLAGS contain -s eg.

ALL_LDFLAGS += $(LDFLAGS) -s

This has the effect of stripping debug symbols from the resulting binary, so debugging is quite hard eg. GDB will be unable to load any debugging symbols. See the GCC man page:

-s Remove all symbol table and relocation information from the executable.

I have checked that removing this from the makefiles allows GDB to find and load the symbols.

The -s flag should probably be restricted to release builds.

detly commented 5 years ago

I'd welcome a workaround for this by the way, I cannot figure out where in the gmake module this is done.

detly commented 5 years ago

It was actually in the GCC toolset code. This in premake5.lua seems to do the trick:

premake.override(
    premake.tools.gcc, "getldflags",
    function(base, cfg)
        premake.tools.gcc.ldflags.symbols = nil
        local flags = base(cfg)
        return flags
    end
)
samsinsane commented 5 years ago

Have you tried symbols "On"?

detly commented 5 years ago

I'm using - Og and - g3, but they definitely don't cancel out the -s.

On Wed., 6 Feb. 2019, 5:04 pm Samuel Surtees <notifications@github.com wrote:

Have you tried symbols "On" https://github.com/premake/premake-core/wiki/symbols?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/premake/premake-core/issues/1238#issuecomment-460910875, or mute the thread https://github.com/notifications/unsubscribe-auth/AAS_x2o9eFmCRpi0Sl3wGMI9tUpmPRy6ks5vKnBUgaJpZM4akdcT .

samsinsane commented 5 years ago

That didn't really answer my question, have you tried using symbols "On"?

detly commented 5 years ago

Sorry, reading too many man pages. I thought you meant On where n is a placeholder.

Yes, adding symbols "On" to premake5.lua (and removing the workaround) removes this flag, thanks! IMO it should be the default when config=Debug, but maybe there are reasons not to?

samsinsane commented 5 years ago

I guess the only reason that it wouldn't default is that configurations just accepts a bunch of strings. I've never really noticed, there's usually a long list of differences between debug and release builds that adding symbols or optimize has never really registered with me.

I guess Premake could contain defaults for arbitrary configurations but that would create inconsistencies and confusion when users create their own configurations. Requiring all settings to be explicitly set for configurations is far more consistent and less confusing overall, just not so much right at the start.

detly commented 5 years ago

That's fair, I wasn't sure what conventions Premake wanted to take on or not. I was confused by the configuration being provided to the gcc.ldflags function, but it looks like it's switching on the OS to work around the issue on OS X, rather than on debug vs. release.