Skip to content

Instantly share code, notes, and snippets.

@Leandros
Created May 5, 2018 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leandros/5bd41243519adcbf4e9b506f606ef205 to your computer and use it in GitHub Desktop.
Save Leandros/5bd41243519adcbf4e9b506f606ef205 to your computer and use it in GitHub Desktop.
#!/bin/bash
cflags="-O3 -std=c++14 -ggdb3 -frecord-gcc-switches"
ldflags="-grecord-gcc-switches -gcolumn-info"
# Cleanup
rm -rf obj
rm test test.pdb
mkdir -p obj
# Objects
g++ $cflags -MMD -MF obj/foo.d -c -o obj/foo.o foo.cpp
g++ $cflags -MMD -MF obj/io.d -c -o obj/io.o io.cpp
# Create our debug info
ld -r -b binary -o obj/cc.o obj/foo.d obj/io.d
objcopy --rename-section=.data=.ccinfo obj/cc.o
objcopy --set-section-flags .ccinfo=debug obj/cc.o
# Link step
g++ $ldflags -o test obj/cc.o obj/foo.o obj/io.o
# Setup debug info
objcopy --only-keep-debug test test.pdb
strip test
objcopy --remove-section .GCC.command.line test
objcopy --remove-section .ccinfo test
objcopy --add-gnu-debuglink=test.pdb test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment