Skip to content

Commit df20009

Browse files
authored
GNU Make: Add new option DEBUG_OPT_LEVEL (#4674)
This does not change the existing behavior, because it's 0 by default. This allows us to increase the optimization level when DEBUG=TRUE. ERF's radiation test problem does not compile with `USE_CUDA=TRUE DEBUG=TRUE`. It fails at link time with ``` /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x21): relocation truncated to fit: R_X86_64_GOTPCRELX against symbol `__libc_start_main@@GLIBC_2.34' defined in .text section in /lib/x86_64-linux-gnu/libc.so.6 /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/Scrt1.o:(.eh_frame+0x20): relocation truncated to fit: R_X86_64_PC32 against `.text' /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/crti.o: in function `_init': (.init+0xb): relocation truncated to fit: R_X86_64_REX_GOTPCRELX against undefined symbol `__gmon_start__' /usr/local/cuda/lib64/libcudart_static.a(cudart_static.o): in function `libcudart_static_a3bf49b59a3e5c73e23c76622c3ce0951724bc73': cuda_runtime_api.cpp:(.text.startup+0x19): relocation truncated to fit: R_X86_64_PC32 against `.data' cuda_runtime_api.cpp:(.text.startup+0x20): relocation truncated to fit: R_X86_64_PC32 against `.data' cuda_runtime_api.cpp:(.text.startup+0x27): relocation truncated to fit: R_X86_64_PC32 against `.data' cuda_runtime_api.cpp:(.text.startup+0x3d): relocation truncated to fit: R_X86_64_PC32 against `.data' /usr/local/cuda/lib64/libcudart_static.a(cudart_static.o): in function `libcudart_static_7bd86af72cd50dfe63513852abf557d8ffc48b76': cudart_global.cpp:(.text.startup+0xbb): relocation truncated to fit: R_X86_64_PC32 against `.bss' cudart_global.cpp:(.text.startup+0xcb): relocation truncated to fit: R_X86_64_PC32 against symbol `__dso_handle' defined in .data.rel.local section in /usr/lib/gcc/x86_64-linux-gnu/13/crtbeginS.o cudart_global.cpp:(.text.startup+0xd2): relocation truncated to fit: R_X86_64_PC32 against `.bss' /usr/local/cuda/lib64/libcudart_static.a(cudart_static.o):(.eh_frame+0x4b18): additional relocation overflows omitted from the output ERF3d.gnu.DEBUG.MPI.CUDA.ex: PC-relative offset overflow in PLT entry for `mlock@@GLIBC_2.2.5' collect2: error: ld returned 1 exit status make: *** [../../../Submodules/AMReX/Tools/GNUMake/Make.rules:64: ERF3d.gnu.DEBUG.MPI.CUDA.ex] Error 1 ``` With `USE_CUDA=TRUE DEBUG=TRUE DEBUG_OPT_LEVEL=1`, it compiles.
1 parent d63eece commit df20009

File tree

16 files changed

+74
-60
lines changed

16 files changed

+74
-60
lines changed

Tools/GNUMake/Make.defs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ else
112112
DEBUG := FALSE
113113
endif
114114

115+
ifdef DEBUG_OPT_LEVEL
116+
DEBUG_OPT_LEVEL := $(strip $(DEBUG_OPT_LEVEL))
117+
else
118+
DEBUG_OPT_LEVEL := 0
119+
endif
120+
115121
ifdef USE_FFT
116122
USE_FFT := $(strip $(USE_FFT))
117123
else

Tools/GNUMake/comps/armclang.mak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ F90FLAGS =
2121

2222
ifeq ($(DEBUG),TRUE)
2323

24-
CXXFLAGS += -g -O0 -ftrapv
25-
CFLAGS += -g -O0 -ftrapv
26-
FFLAGS += -g -O0 -ftrapv
27-
F90FLAGS += -g -O0 -ftrapv
24+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ftrapv
25+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ftrapv
26+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ftrapv
27+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -ftrapv
2828

2929
else
3030

Tools/GNUMake/comps/cray.mak

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ endif
3434
ifeq ($(DEBUG),TRUE)
3535

3636
ifeq ($(CRAY_IS_CLANG_BASED),TRUE)
37-
CXXFLAGS += -g -O0
38-
CFLAGS += -g -O0
39-
FFLAGS += -g -O0 -e i -K trap=fp
40-
F90FLAGS += -g -O0 -e i -K trap=fp
37+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL)
38+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL)
39+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -e i -K trap=fp
40+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -e i -K trap=fp
4141
else
4242
GENERIC_COMP_FLAGS += -K trap=fp
4343

44-
CXXFLAGS += -g -O0
45-
CFLAGS += -g -O0
46-
FFLAGS += -g -O0 -e i
47-
F90FLAGS += -g -O0 -e i
44+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL)
45+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL)
46+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -e i
47+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -e i
4848
endif
4949

5050
else

Tools/GNUMake/comps/dpcpp.mak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ endif
2424

2525
ifeq ($(DEBUG),TRUE)
2626

27-
CXXFLAGS += -g -O0 #-ftrapv
28-
CFLAGS += -g -O0 #-ftrapv
27+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL) #-ftrapv
28+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL) #-ftrapv
2929

30-
FFLAGS += -g -O0 -traceback -check bounds,uninit,pointers
31-
F90FLAGS += -g -O0 -traceback -check bounds,uninit,pointers
30+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -traceback -check bounds,uninit,pointers
31+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -traceback -check bounds,uninit,pointers
3232

3333
else
3434

Tools/GNUMake/comps/gnu.mak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ CXXFLAGS += -Werror=return-type
8383
CFLAGS += -Werror=return-type
8484

8585
ifeq ($(DEBUG),TRUE)
86-
CXXFLAGS += -g -O0 -ggdb -ftrapv
87-
CFLAGS += -g -O0 -ggdb -ftrapv
86+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ggdb -ftrapv
87+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ggdb -ftrapv
8888
else
8989
CXXFLAGS += -g1 -O3
9090
CFLAGS += -g1 -O3
@@ -176,8 +176,8 @@ F90FLAGS =
176176

177177
ifeq ($(DEBUG),TRUE)
178178

179-
FFLAGS += -g -O0 -ggdb -fcheck=bounds -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero -finit-real=snan -finit-integer=2147483647 -ftrapv
180-
F90FLAGS += -g -O0 -ggdb -fcheck=bounds -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero -finit-real=snan -finit-integer=2147483647 -ftrapv
179+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ggdb -fcheck=bounds -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero -finit-real=snan -finit-integer=2147483647 -ftrapv
180+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -ggdb -fcheck=bounds -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero -finit-real=snan -finit-integer=2147483647 -ftrapv
181181

182182
else
183183

Tools/GNUMake/comps/hip.mak

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,15 @@ endif # BL_NO_FORT
8484
ifeq ($(HIP_COMPILER),clang)
8585

8686
ifeq ($(DEBUG),TRUE)
87-
CXXFLAGS += -g -O1 -munsafe-fp-atomics
88-
CFLAGS += -g -O0
87+
ifeq ($(DEBUG_OPT_LEVEL),0)
88+
CXXFLAGS += -g -O1 -munsafe-fp-atomics
89+
else
90+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL) -munsafe-fp-atomics
91+
endif
92+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL)
8993

90-
FFLAGS += -g -O0 -ggdb -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero -finit-real=snan -finit-integer=2147483647 -ftrapv
91-
F90FLAGS += -g -O0 -ggdb -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero -finit-real=snan -finit-integer=2147483647 -ftrapv
94+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ggdb -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero -finit-real=snan -finit-integer=2147483647 -ftrapv
95+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -ggdb -fbounds-check -fbacktrace -Wuninitialized -Wunused -ffpe-trap=invalid,zero -finit-real=snan -finit-integer=2147483647 -ftrapv
9296

9397
else # DEBUG=FALSE flags
9498

Tools/GNUMake/comps/ibm.mak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ CFLAGS =
4949

5050
ifeq ($(DEBUG),TRUE)
5151

52-
CXXFLAGS += -g -O0
53-
CFLAGS += -g -O0
52+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL)
53+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL)
5454

5555
else
5656

@@ -104,8 +104,8 @@ F90FLAGS =
104104

105105
ifeq ($(DEBUG),TRUE)
106106

107-
FFLAGS += -g -O0
108-
F90FLAGS += -g -O0
107+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL)
108+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL)
109109

110110
else
111111

Tools/GNUMake/comps/intel-classic.mak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ COMP_VERSION = $(intel_version)
2525

2626
ifeq ($(DEBUG),TRUE)
2727

28-
CXXFLAGS += -g -O0 -traceback -Wcheck
29-
CFLAGS += -g -O0 -traceback -Wcheck
30-
FFLAGS += -g -O0 -traceback -check bounds,uninit,pointers
31-
F90FLAGS += -g -O0 -traceback -check bounds,uninit,pointers
28+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL) -traceback -Wcheck
29+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL) -traceback -Wcheck
30+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -traceback -check bounds,uninit,pointers
31+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -traceback -check bounds,uninit,pointers
3232

3333
else
3434

Tools/GNUMake/comps/intel-llvm.mak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ COMP_VERSION = $(intel_version)
2525

2626
ifeq ($(DEBUG),TRUE)
2727

28-
CXXFLAGS += -g -O0 -ftrapv
29-
CFLAGS += -g -O0 -ftrapv
30-
FFLAGS += -g -O0 -ftrapuv -check bounds,pointers,uninit -traceback
31-
F90FLAGS += -g -O0 -ftrapuv -check bounds,pointers,uninit -traceback
28+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ftrapv
29+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ftrapv
30+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ftrapuv -check bounds,pointers,uninit -traceback
31+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -ftrapuv -check bounds,pointers,uninit -traceback
3232

3333
else
3434

Tools/GNUMake/comps/llvm-flang.mak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ COMP_VERSION = $(clang_version)
2323

2424
ifeq ($(DEBUG),TRUE)
2525

26-
CXXFLAGS += -g -O0 -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -ftrapv
27-
CFLAGS += -g -O0 -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -ftrapv
26+
CXXFLAGS += -g -O$(DEBUG_OPT_LEVEL) -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -ftrapv
27+
CFLAGS += -g -O$(DEBUG_OPT_LEVEL) -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -ftrapv
2828

29-
FFLAGS += -g -O0 -ggdb -Wuninitialized -Wunused -ftrapv
30-
F90FLAGS += -g -O0 -ggdb -Wuninitialized -Wunused -ftrapv
29+
FFLAGS += -g -O$(DEBUG_OPT_LEVEL) -ggdb -Wuninitialized -Wunused -ftrapv
30+
F90FLAGS += -g -O$(DEBUG_OPT_LEVEL) -ggdb -Wuninitialized -Wunused -ftrapv
3131

3232
else
3333

0 commit comments

Comments
 (0)