Date: Tue, 18 Jan 2022 13:03:46 +0000 (UTC) From: Sagara Wijetunga <sagarawmw@yahoo.com> To: "freebsd-questions@FreeBSD.org" <freebsd-questions@FreeBSD.org> Subject: How to disable clang AddressSanitizer instrumentation for a function on FreeBSD? Message-ID: <366091554.1057409.1642511026145@mail.yahoo.com> References: <366091554.1057409.1642511026145.ref@mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
------=_Part_1057408_100966155.1642511026143 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi=C2=A0 I'm trying to skip=C2=A0clang AddressSanitizer instrumentation for=C2=A0isM= atch(void *ptr) function. How to do this on FreeBSD?=C2=A0 My test program: #include <string.h>#include <stdio.h>#include <stdlib.h> =C2=A0#define=C2=A0 PATTERN1=C2=A0 =C2=A00x4ffcf694=C2=A0static unsigned ch= ar pattern1[] =3D {0x4f,0xfc,0xf6,0x94}; __attribute__((no_sanitize("address")))=C2=A0int isMatch(void *ptr); int main(int argc, char *argv[]){=C2=A0int rv =3D 0;=C2=A0void *ptr =3D NUL= L; =C2=A0ptr =3D malloc(4);=C2=A0if (!ptr)=C2=A0 =C2=A0 {=C2=A0 =C2=A0 =C2=A0p= rintf("No memory.");=C2=A0 =C2=A0 =C2=A0exit(1);=C2=A0 =C2=A0 }=C2=A0=C2=A0= /* Copy PATTERN1 marker to the allocated block */=C2=A0memcpy(ptr, pattern1= , sizeof(pattern1)); =C2=A0/*=C2=A0 TEST 1: Correct case.=C2=A0*/=C2=A0printf("TEST 1: Correct c= ase.\n");=C2=A0rv =3D isMatch(ptr);=C2=A0if (rv =3D=3D 1)=C2=A0 =C2=A0 prin= tf("Matched\n");=C2=A0else=C2=A0 =C2=A0 printf("NOT Matched\n"); =C2=A0/*=C2=A0 TEST 2: ptr - 1000=C2=A0*/=C2=A0printf("TEST 2: ptr - 1000\n= ");=C2=A0rv =3D isMatch(ptr - 1000);=C2=A0if (rv =3D=3D 1)=C2=A0 =C2=A0 pri= ntf("Matched\n");=C2=A0else=C2=A0 =C2=A0 printf("NOT Matched\n"); } __attribute__((no_sanitize("address")))=C2=A0int isMatch(void *ptr){=C2=A0i= f ((memcmp(ptr, (void *)pattern1, sizeof(pattern1)) =3D=3D 0))=C2=A0 =C2=A0= return 1;=C2=A0=C2=A0return 0;} /usr/local/bin/clang13 prog.c -O1 -g -fsanitize=3Daddress -fno-omit-frame-p= ointer -Wall -O -I. -I/usr/local/include -L. -L/usr/local/lib -o prog When run I get following:./progTEST 1: Correct case.MatchedTEST 2: ptr - 10= 00AddressSanitizer:DEADLYSIGNAL=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D29072=3D=3DERROR: AddressSanitizer: SEGV on unknown address 0x601f= fff00010 (pc 0x0000002bb794 bp 0x7fffffffea30 sp 0x7fffffffea30 T0)=3D=3D29= 072=3D=3DThe signal is caused by a READ memory access.=C2=A0 =C2=A0 #0 0x2b= b794 in isMatch path/prog.c:67:7=C2=A0 =C2=A0 #1 0x2bb73e in main path/prog= .c:56:7=C2=A0 =C2=A0 #2 0x236d3f in _start /usr/src/lib/csu/amd64/crt1_c.c:= 75:7=C2=A0 =C2=A0 #3 0x8002e2007=C2=A0 (<unknown module>) AddressSanitizer can not provide additional info.SUMMARY: AddressSanitizer:= SEGV path/prog.c:67:7 in isMatch=3D=3D29072=3D=3DABORTING Appreciate any help. Best regardsSagara =C2=A0 ------=_Part_1057408_100966155.1642511026143 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <html><head></head><body><div class=3D"yahoo-style-wrap" style=3D"font-fami= ly:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div dir= =3D"ltr" data-setdir=3D"false">Hi </div><div dir=3D"ltr" data-setdir= =3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"false">I'm trying to s= kip <span>clang AddressSanitizer instrumentation for <span>isMatc= h(void *ptr) function. How to do this on FreeBSD? </span></span></div>= <div dir=3D"ltr" data-setdir=3D"false"><span><span><br></span></span></div>= <div dir=3D"ltr" data-setdir=3D"false">My test program:</div><div dir=3D"lt= r" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"false"><= div><div>#include <string.h></div><div>#include <stdio.h></div>= <div>#include <stdlib.h></div><div><br></div><div> #define = PATTERN1 0x4ffcf694</div><div> static unsigned char patte= rn1[] =3D {0x4f,0xfc,0xf6,0x94};</div><div><br></div><div><br></div><div>__= attribute__((no_sanitize("address"))) </div><div>int isMatch(void *ptr= );</div><div><br></div><div>int main(int argc, char *argv[])</div><div>{</d= iv><div> int rv =3D 0;</div><div> void *ptr =3D NULL;</div><div><= br></div><div> ptr =3D malloc(4);</div><div> if (!ptr)</div><div>= {</div><div> printf("No memory.");</div><d= iv> exit(1);</div><div> }</div><div> <= /div><div> /* Copy PATTERN1 marker to the allocated block */</div><div= > memcpy(ptr, pattern1, sizeof(pattern1));</div><div><br></div><div>&n= bsp;/*</div><div> TEST 1: Correct case.</div><div> */</div><div>= printf("TEST 1: Correct case.\n");</div><div> rv =3D isMatch(ptr= );</div><div> if (rv =3D=3D 1)</div><div> printf("Matched= \n");</div><div> else</div><div> printf("NOT Matched\n");= </div><div><br></div><div><br></div><div> /*</div><div> TEST 2: = ptr - 1000</div><div> */</div><div> printf("TEST 2: ptr - 1000\n"= );</div><div> rv =3D isMatch(ptr - 1000);</div><div> if (rv =3D= =3D 1)</div><div> printf("Matched\n");</div><div> else</d= iv><div> printf("NOT Matched\n");</div><div><br></div><div>}</= div><div><br></div><div>__attribute__((no_sanitize("address"))) </div>= <div>int isMatch(void *ptr)</div><div>{</div><div> if ((memcmp(ptr, (v= oid *)pattern1, sizeof(pattern1)) =3D=3D 0))</div><div> return= 1;</div><div> </div><div> return 0;</div><div>}</div><div><br></= div></div><div><br></div></div><div dir=3D"ltr" data-setdir=3D"false"><span= >/usr/local/bin/clang13 prog.c -O1 -g -fsanitize=3Daddress -fno-omit-frame-= pointer -Wall -O -I. -I/usr/local/include -L. -L/usr/local/lib -o prog</spa= n></div><div dir=3D"ltr" data-setdir=3D"false"><span><br></span></div><div = dir=3D"ltr" data-setdir=3D"false"><span><br></span></div><div dir=3D"ltr" d= ata-setdir=3D"false"><span>When run I get following:</span></div><div dir= =3D"ltr" data-setdir=3D"false"><div><div>./prog</div><div>TEST 1: Correct c= ase.</div><div>Matched</div><div>TEST 2: ptr - 1000</div><div>AddressSaniti= zer:DEADLYSIGNAL</div><div>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</d= iv><div>=3D=3D29072=3D=3DERROR: AddressSanitizer: SEGV on unknown address 0= x601ffff00010 (pc 0x0000002bb794 bp 0x7fffffffea30 sp 0x7fffffffea30 T0)</d= iv><div>=3D=3D29072=3D=3DThe signal is caused by a READ memory access.</div= ><div> #0 0x2bb794 in isMatch path/prog.c:67:7</div><div> = ; #1 0x2bb73e in main path/prog.c:56:7</div><div> #2 0x= 236d3f in _start /usr/src/lib/csu/amd64/crt1_c.c:75:7</div><div> &nbs= p; #3 0x8002e2007 (<unknown module>)</div><div><br></div><div>A= ddressSanitizer can not provide additional info.</div><div>SUMMARY: Address= Sanitizer: SEGV path/prog.c:67:7 in isMatch</div><div>=3D=3D29072=3D=3DABOR= TING</div><div><br></div></div><div dir=3D"ltr" data-setdir=3D"false">Appre= ciate any help.</div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div = dir=3D"ltr" data-setdir=3D"false">Best regards</div><div dir=3D"ltr" data-s= etdir=3D"false">Sagara</div><div dir=3D"ltr" data-setdir=3D"false"><br></di= v></div><div dir=3D"ltr" data-setdir=3D"false"><span> </span><br></div= ><div dir=3D"ltr" data-setdir=3D"false"><br></div></div></body></html> ------=_Part_1057408_100966155.1642511026143--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?366091554.1057409.1642511026145>