Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 574448 - Building a project with debug option sanitize address
Summary: Building a project with debug option sanitize address
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-build (show other bugs)
Version: 10.3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 10.4.0   Edit
Assignee: cdt-build-inbox@eclipse.org CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-24 13:45 EDT by Guenter Stoehr CLA
Modified: 2021-09-15 10:31 EDT (History)
2 users (show)

See Also:


Attachments
Two screenshots of debug settings and eclipse IDE version. (315.96 KB, application/gzip)
2021-06-24 13:45 EDT, Guenter Stoehr CLA
no flags Details
Manual debug settings in project HelloWorld. (179.39 KB, image/png)
2021-06-24 14:53 EDT, Guenter Stoehr CLA
no flags Details
Linker Flag -fsanitze=address (141.84 KB, image/png)
2021-06-25 10:18 EDT, Guenter Stoehr CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Guenter Stoehr CLA 2021-06-24 13:45:35 EDT
Created attachment 286678 [details]
Two screenshots of debug settings and eclipse IDE version.

When I try to build the project, I get an error message:

Info: Internal Builder is used for build
gcc -O0 -g3 -fsanitize-address -fsanitize=leak -fsanitize=undefined -pedantic -Wall -c -fmessage-length=0 -o src/bst.o ../src/bst.c 
gcc: error: unrecognized command-line option ‘-fsanitize-address’; did you mean ‘-fsanitize=address’?

You can see the selected debugging flags in the first screenshot.

Sorry, I'm not sure about the version. I only can see 4.20.0 (2021-06). See second screenshot.
Comment 1 Jonah Graham CLA 2021-06-24 14:13:57 EDT
Thanks for the bug report. It looks like there was some typos in Bug 266305 work. Thank you for brining them to our attention.
Comment 2 Eclipse Genie CLA 2021-06-24 14:30:00 EDT
New Gerrit change created: https://git.eclipse.org/r/c/cdt/org.eclipse.cdt/+/182419
Comment 3 Jonah Graham CLA 2021-06-24 14:32:37 EDT
I have prepared a fix, in the meantime, please use the workaround of manually putting the correct flag in "Other debugging flags"
Comment 4 Guenter Stoehr CLA 2021-06-24 14:52:50 EDT
Ok, I did it, but got more errors. So I created a Hello World Project by the wizard and entered manually "-fsantize=address". See screenshot.

This is, what I got:

20:49:22 **** Incremental Build of configuration Debug for project HelloWorld ****
make all 
Building target: HelloWorld
Invoking: GCC C Linker
gcc  -o "HelloWorld" ./src/HelloWorld.o   
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: ./src/HelloWorld.o: in function `_sub_D_00099_0':
/mnt/datalnx/data_gs/Entwicklung/C/eclipse-workspace/HelloWorld/Debug/../src/HelloWorld.c:17: undefined reference to `__asan_unregister_globals'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: ./src/HelloWorld.o: in function `_sub_I_00099_1':
/mnt/datalnx/data_gs/Entwicklung/C/eclipse-workspace/HelloWorld/Debug/../src/HelloWorld.c:17: undefined reference to `__asan_init'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: /mnt/datalnx/data_gs/Entwicklung/C/eclipse-workspace/HelloWorld/Debug/../src/HelloWorld.c:17: undefined reference to `__asan_version_mismatch_check_v8'
/usr/lib64/gcc/x86_64-suse-linux/11/../../../../x86_64-suse-linux/bin/ld: /mnt/datalnx/data_gs/Entwicklung/C/eclipse-workspace/HelloWorld/Debug/../src/HelloWorld.c:17: undefined reference to `__asan_register_globals'
collect2: error: ld returned 1 exit status
make: *** [makefile:46: HelloWorld] Fehler 1
"make all" terminated with exit code 2. Build might be incomplete.

20:49:22 Build Failed. 7 errors, 0 warnings. (took 318ms)
Comment 5 Guenter Stoehr CLA 2021-06-24 14:53:39 EDT
Created attachment 286679 [details]
Manual debug settings in project HelloWorld.
Comment 6 Jonah Graham CLA 2021-06-24 15:46:41 EDT
For those issues please consult gcc docs and support channels. If there are changes to CDT that it leads to we can make them.

https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
https://github.com/google/sanitizers/wiki/AddressSanitizer
Comment 8 Guenter Stoehr CLA 2021-06-25 02:27:28 EDT
(In reply to Jonah Graham from comment #6)
> For those issues please consult gcc docs and support channels. If there are
> changes to CDT that it leads to we can make them.
> 
> https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
> https://github.com/google/sanitizers/wiki/AddressSanitizer

It's not a gcc issue. When I compile HelloWorld.c manually in a terminal with "gcc -fsanitize=address -o HelloWorld.o HelloWorld.c", everything is ok. I get those errors, mentioned in comment #4 only when building HelloWorld.c in Eclipse.
Comment 9 Jonah Graham CLA 2021-06-25 08:07:45 EDT
Ok. Your terminal command line is compile and link, my guess is that the sanitize command line option needs to be specified at link time too. Please add the option to the linker flags. If that works, let me know and we'll look at how to provide them in both places.
Comment 10 Guenter Stoehr CLA 2021-06-25 10:18:16 EDT
Created attachment 286687 [details]
Linker Flag -fsanitze=address



When I set the linker flag as shown in the attachment,it works and HelloWorld is compiled and linked without an error.

I found another issue:

16:12:52 **** Incremental Build of configuration Debug for project HelloWorld ****
make all 
Building file: ../src/HelloWorld.c
Invoking: GCC C Compiler
gcc -O0 -g3 -fsanitize=address -fsanitize-pointer-compare -fsanitize=pointer-subtract -Wall -c -fmessage-length=0 -MMD -MP -MF"src/HelloWorld.d" -MT"src/HelloWorld.o" -o "src/HelloWorld.o" "../src/HelloWorld.c"
gcc: error: unrecognized command-line option ‘-fsanitize-pointer-compare’; did you mean ‘-fsanitize=pointer-compare’?
make: *** [src/subdir.mk:20: src/HelloWorld.o] Fehler 1
"make all" terminated with exit code 2. Build might be incomplete.

And another question: How can I get the fix?
Comment 11 Jonah Graham CLA 2021-06-25 10:38:54 EDT
(In reply to Guenter Stoehr from comment #10)
> Created attachment 286687 [details]
> Linker Flag -fsanitze=address
> 
> 
> 
> When I set the linker flag as shown in the attachment,it works and
> HelloWorld is compiled and linked without an error.

Great. Thanks for confirming. 

> 
> I found another issue:

My earlier commit fixed this case too. 

> 
> And another question: How can I get the fix?

It will be part of the next release. You can try out latest master build https://ci.eclipse.org/cdt/job/cdt-master/lastSuccessfulBuild/artifact/releng/org.eclipse.cdt.repo/target/repository/ 

If this is blocker for you we may be able to spin a bug fix release based on last release.
Comment 12 Jonah Graham CLA 2021-09-15 10:31:28 EDT
I think we are done here - just never marked it resolved until now. Please advise if something is missing.