Message ID | tencent_07F41222A743779181827FB2F0EAE7BECE08@qq.com |
---|---|
State | New |
Headers | show |
Series | Enable Dead Code Elimination | expand |
On Sat, Aug 24, 2024 at 4:22 PM Kele Zhang <1952088712@qq.com> wrote: > > Remove `-g` from default CFLAGS as it should not be used in production > builds. Adjust optimization level to `-Og` when DEBUG is enabled. The production build does not use ELF images to program onto the board but the plain binary image instead. So `-g`should be fine. As for `-Og` vs. `-O0` I prefer using `-O0` as `-Og` sometimes breaks debugging. > > Signed-off-by: Kele Zhang <1952088712@qq.com> > Signed-off-by: Yuan Tan <tanyuan@tinylab.org> > --- > Makefile | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/Makefile b/Makefile > index 9abea9f..bcec588 100644 > --- a/Makefile > +++ b/Makefile > @@ -346,9 +346,9 @@ GENFLAGS += $(libsbiutils-genflags-y) > GENFLAGS += $(platform-genflags-y) > GENFLAGS += $(firmware-genflags-y) > > -CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections -Wl,--gc-sections > +CFLAGS = -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections -Wl,--gc-sections > ifneq ($(DEBUG),) > -CFLAGS += -O0 -Wl,--print-gc-sections > +CFLAGS += -Og -Wl,--print-gc-sections > else > CFLAGS += -O2 > endif Regards, Bin
On 28 Aug 2024, at 15:50, Bin Meng <bmeng.cn@gmail.com> wrote: > > On Sat, Aug 24, 2024 at 4:22 PM Kele Zhang <1952088712@qq.com> wrote: >> >> Remove `-g` from default CFLAGS as it should not be used in production >> builds. Adjust optimization level to `-Og` when DEBUG is enabled. > > The production build does not use ELF images to program onto the board > but the plain binary image instead. So `-g`should be fine. And even for boards that do, -g is the right thing to do. If you don’t want debugging symbols, strip the binary, but it’s useful to default to including them; distributions generally do exactly that, stripping the installed binary but keeping the debug symbols around in a separate .debug file. Debug symbols also aren’t loaded into memory, they only exist on disk, so the only cost is a bit of disk space. Jess
diff --git a/Makefile b/Makefile index 9abea9f..bcec588 100644 --- a/Makefile +++ b/Makefile @@ -346,9 +346,9 @@ GENFLAGS += $(libsbiutils-genflags-y) GENFLAGS += $(platform-genflags-y) GENFLAGS += $(firmware-genflags-y) -CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections -Wl,--gc-sections +CFLAGS = -Wall -Werror -ffreestanding -nostdlib -fno-stack-protector -fno-strict-aliasing -ffunction-sections -fdata-sections -Wl,--gc-sections ifneq ($(DEBUG),) -CFLAGS += -O0 -Wl,--print-gc-sections +CFLAGS += -Og -Wl,--print-gc-sections else CFLAGS += -O2 endif