2013-04-21 18 views
27

Vorrei usare clang address sanitizer su OSX Mountain Lion, perché Valgrind ha problemi con il controllo della memoria su questa piattaforma. Ma quando ho avuto l'-fsanitize=address durante il tempo di compilazione (come vedo in questa pagina: http://clang.llvm.org/docs/AddressSanitizer.html), ho ottenuto questo errore: clang: error: argument unused during compilation: '-fsanitize=address'Clang Address Sanitizer su OS X

Quindi, la mia domanda è come utilizzare Indirizzo Clang Sanitizer su OS X? Se non posso usarlo, quale strumento posso usarlo?

Ho clang di download con Xcode ed è aggiornato. (Forse questa versione non è affrontare disinfettante costruire con esso)

risposta

6

Secondo la fonte (in particolare se si afferra il clang-425.0.24 fascio dal Apple's Open Source Site, il file di test src/tools/clang/test/Driver/darwin-asan-nofortify.c:

// rdar://11496765, rdar://12417750 
// -faddress-sanitizer is not currently supported. 
// XFAIL: * 

E, naturalmente, ci è un errore utilizzando -faddress-sanitizer, così sembra che sotto OS X, è necessario costruire clang se stessi da fonte più recente, al fine di ottenere l'indirizzo disinfettante.

opzione della riga di comando

Provare a utilizzare -faddress-sanitizer anziché -fsanitize=address. La versione di Apple sembra essere basata su una versione precedente di CLANG e, se si esegue clang --help, i disinfettanti sono tutti di questo formato in questa versione.

+4

ho ottenuto un errore troppo: 'clang: errore: opzione non supportata '-faddress-sanitizer''. Tuttavia, in 'clang --help' posso vedere questa opzione – Guillaume

+0

@gaige: il problema è che Apple sta implementando una ** versione ** più vecchia di Clang, che utilizzava ancora il vecchio' -faddress-sanitizer'. Il più recente '-fsanitize = address' si unì più tardi, quando gli altri disinfettanti furono aggiunti. – 0xC0000022L

+0

@ 0xC0000022L Scusate, pensavo di fare quel punto in alto quando ho detto "dovrete costruirvi un clang da una fonte più recente". Certo, non dice esplicitamente che la versione di Apple è più vecchia, ma suggerisce di costruire da una versione più recente. Aggiornerò la lingua per renderla più chiara. – gaige

12

Indirizzo Sanitizer è stato aggiunto come una nuova funzionalità in Xcode 7.

utilizzare il flag Runtime Sanitization>Enable Address Sanitizer nel vostro schema per abilitare l'opzione.

git sarà poi mostrato questa modifica al tuo .xcscheme del file:

enableAddressSanitizer = "YES" 

Dal documento New Features in Xcode 7:

Address Sanitizer. Xcode 7 can build your app with instrumentation designed to catch and debug memory corruption using the address sanitizer.

Objective-C and C code is susceptible to memory corruption issues such as stack and heap buffer overruns and use-after-free issues. When these memory violations occur, your app can crash unpredictably or display odd behavior. Memory corruption issues are difficult to track down because the crashes and odd behavior are often hard to reproduce and the cause can be far from the origin of the problem.

Enable Address Sanitizer

You enable the address sanitizer in the build scheme. Once enabled, added instrumentation is built into the app to catch memory violations immediately, enabling you to inspect the problem right at the place where it occurs. Other diagnostic information is provided as well, such as the relationship between the faulty address and a valid object on the heap and allocation/deallocation information, which helps you pinpoint and fix the problem quickly.

Address sanitizer is efficient—fast enough to be used regularly, as well as with interactive applications. It is supported on OS X, in the Simulator, and on iOS devices.