llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.63k stars 11.83k forks source link

Crash: Unknown addressing mode for CP reference! #18180

Closed llvmbot closed 1 year ago

llvmbot commented 10 years ago
Bugzilla Link 17806
Version 3.3
OS Linux
Attachments Attached files as requested.
Reporter LLVM Bugzilla Contributor

Extended Description

Clang just crashed on me, it asked me to file this bug, so I am.

This is the command line output:

Compiling (clang apple/llvm-armv7m/3.3) "lwip/src/core/dns.c" Unknown addressing mode for CP reference! UNREACHABLE executed at /home/elvin/GIT/embedded-tools/llvm-clang-3.3/llvm-source/lib/Target/ARM/ARMConstantIslandPass.cpp:734! 0 armv7m-none-eabi-clang 0x09dca2ef llvm::sys::PrintStackTrace(_IO_FILE) + 47 1 armv7m-none-eabi-clang 0x09dca54f 2 armv7m-none-eabi-clang 0x09dc9714 3 0x40022400 __kernel_sigreturn + 0 4 0x40022424 __kernel_vsyscall + 16 5 libc.so.6 0x401b51df gsignal + 79 6 libc.so.6 0x401b8825 abort + 373 7 armv7m-none-eabi-clang 0x09daf9fc 8 armv7m-none-eabi-clang 0x093b6480 9 armv7m-none-eabi-clang 0x0969519a llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 186 10 armv7m-none-eabi-clang 0x09cd124c llvm::FPPassManager::runOnFunction(llvm::Function&) + 636 11 armv7m-none-eabi-clang 0x09cd12b8 llvm::FPPassManager::runOnModule(llvm::Module&) + 56 12 armv7m-none-eabi-clang 0x09cd0d24 llvm::MPPassManager::runOnModule(llvm::Module&) + 692 13 armv7m-none-eabi-clang 0x09cd0f0c llvm::PassManagerImpl::run(llvm::Module&) + 236 14 armv7m-none-eabi-clang 0x09cd0fc6 llvm::PassManager::run(llvm::Module&) + 38 15 armv7m-none-eabi-clang 0x08507313 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::Module, clang::BackendAction, llvm::raw_ostream) + 3747 16 armv7m-none-eabi-clang 0x08504a99 17 armv7m-none-eabi-clang 0x086c833a clang::ParseAST(clang::Sema&, bool, bool) + 410 18 armv7m-none-eabi-clang 0x0835e3bf clang::ASTFrontendAction::ExecuteAction() + 111 19 armv7m-none-eabi-clang 0x08502c12 clang::CodeGenAction::ExecuteAction() + 50 20 armv7m-none-eabi-clang 0x0835edd8 clang::FrontendAction::Execute() + 248 21 armv7m-none-eabi-clang 0x0834041d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 301 22 armv7m-none-eabi-clang 0x08325898 clang::ExecuteCompilerInvocation(clang::CompilerInstance) + 1608 23 armv7m-none-eabi-clang 0x0831de30 cc1_main(char const, char const, char const, void) + 1008 24 armv7m-none-eabi-clang 0x08307eb9 main + 809 25 libc.so.6 0x401a04d3 __libc_start_main + 243 26 armv7m-none-eabi-clang 0x0831d8b1 Stack dump:

  1. Program arguments: /usr/local/nestlabs-20131024-9c2cfe5/toolchains/llvm/3.3/armv7m/bin/armv7m-none-eabi-clang -cc1 -triple thumbv7em-none--eabi -S -disable-free -main-file-name dns.c -mrelocation-model static -fmath-errno -mconstructor-aliases -target-abi aapcs -target-cpu cortex-m4 -msoft-float -mfloat-abi soft -target-feature +soft-float -target-feature +soft-float-abi -target-feature -neon -target-linker-version 2.22 -g -ffunction-sections -fdata-sections -coverage-file /tmp/dns-0KUIKq.s -nostdsysteminc -nobuiltininc -resource-dir /usr/local/nestlabs-20131024-9c2cfe5/toolchains/llvm/3.3/armv7m/bin/../lib/clang/3.3 -dependency-file .depend/Makefile/topaz/apple/llvm-armv7m/3.3/development/dns.d -sys-header-deps -MP -MT .build/Makefile/topaz/apple/llvm-armv7m/3.3/development/dns.o -isystem /usr/local/nestlabs/toolchains/llvm/3.3/armv7m/lib/clang/3.3/include -isystem /usr/local/nestlabs/toolchains/llvm/3.3/armv7m/lib/clang/3.3/include -U __STRICT_ANSI -D FINAL=final -D BUILD_PRODUCT_TOPAZ -D BUILD_PRODUCT="topaz" -D NL_FREERTOS -D WICED_PAYLOAD_MTU=1536 -D NL_WEAVE_LWIP=1 -D NL_BOOTLOADER_SIZE=32768 -D NL_APPLICATION_VECTORS_ADDRESS=0x8000 -D NL_APPLICATION_VERSION_ADDRESS=0x81e0 -D NL_APPLICATION_RAM_VECTOR_ADDRESS=0x1fff0000 -D NL_APPLICATION_RAM_BASE_ADDRESS=0x1fff0000 -D NL_APPLICATION_RAM_TOP_ADDRESS=0x20010000 -D NL_APPLICATION_RAM_RETAIN_ADDRESS=0x20000000 -D NL_APPLICATION_RAM_RETAIN_SIZE=0x4000 -D NL_APPLICATION_PRESERVATION_MODE_OFFS=0x3fd4 -D NL_APPLICATION_SENSOR_FAIL_OFFS=0x3fd8 -D NL_APPLICATION_HOB_OFFS=0x3fdc -D NL_APPLICATION_FLASH_BASE=0x8000 -D NL_APPLICATION_FLASH_SIZE=0x80000 -D MINIMUM_STACK_SIZE=0x800 -D AUPD_STACK_SIZE=0x1000 -D NL_BOOTLOADER_VECTORS_ADDRESS=0x0 -D NL_BOOTLOADER_RAM_BASE_ADDRESS=0x2000C000 -D NL_FLASH_MAGIC_ADDRESS=0x00000400 -D NL_FEATURE_SIMULATEABLE_TIME=0 -D NL_FEATURE_SIMULATEABLE_HW=0 -D NL_FEATURE_SIMULATEABLE_ALARMS=0 -D NL_FEATURE_SIMULATEABLE_BP_SENSORS=0 -D NL_FEATURE_SIMULATEABLE_ULTRASOUND_SENSOR=0 -D BUILD_CONFIG="development" -D BUILD_CONFIG_DEVELOPMENT -D DEBUG=1 -D NO_SIG_CHECK=1 -I /home/barry/devel/dolomite/production/sw/nestlabs/include/product/topaz -I /home/barry/devel/dolomite/production/sw/nestlabs/include -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/nestlabs/lib/nllibc-lite/usr/include -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/newlib/usr/arm-none-eabi/include -I ./lwip/src/include -I ./lwip/src/include/ipv4 -I ./lwip/src/include/ipv6 -I os/freertos -I products -I products/topaz -I /home/barry/devel/dolomite/production/sw/tps/freertos/products/topaz -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/freertos/include -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/newlib/usr/arm-none-eabi/include -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/bcm/wiced/WWD/include -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/bcm/wiced/. -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/bcm/wiced/Network/LwIP -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/bcm/wiced/RTOS/FreeRTOS -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/bcm/wiced/WWD/internal/Bus_protocols/SPI -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/bcm/wiced/WWD/internal/Network/LwIP -I /home/barry/devel/dolomite/production/results/topaz/apple/llvm-armv7m/3.3/development/sw/tps/bcm/wiced/internal/Network/LwIP -I ./ -Os -Wall -Wchar-subscripts -Wformat -Wparentheses -Wreturn-type -Wsequence-point -Wshadow -Wuninitialized -Wunused -Wimplicit -Wmissing-prototypes -Wstrict-prototypes -fno-dwarf-directory-asm -fdebug-compilation-dir /home/barry/devel/dolomite/production/sw/tps/lwip -ferror-limit 19 -fmessage-length 210 -ffreestanding -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fobjc-default-synthesize-properties -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -mllvm -arm-dont-use-movt -mllvm -lowregs-stack-align -o /tmp/dns-0KUIKq.s -x c lwip/src/core/dns.c
  2. parser at end of file
  3. Code generation
  4. Running pass 'Function Pass Manager' on module 'lwip/src/core/dns.c'.
  5. Running pass 'ARM constant island placement and branch shortening pass' on function '@dns_check_entry' armv7m-none-eabi-clang: error: unable to execute command: Aborted (core dumped) armv7m-none-eabi-clang: error: clang frontend command failed due to signal (use -v to see invocation) nestlabs-clang version 3.3 (tags/RELEASE_33/final 187361) (based on LLVM 3.3) Target: armv7m-none--eabi Thread model: posix armv7m-none-eabi-clang: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. armv7m-none-eabi-clang: note: diagnostic msg:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: armv7m-none-eabi-clang: note: diagnostic msg: /tmp/dns-UoFhjM.c armv7m-none-eabi-clang: note: diagnostic msg: /tmp/dns-UoFhjM.sh armv7m-none-eabi-clang: note: diagnostic msg:


llvmbot commented 10 years ago

It really doesn't like my function

/**

static u16_t new_query_id(u8_t i) {

if LWIP_DNS_RAND_ID

if !defined(LWIP_RAND)

error "LWIP_RAND must be specified if LWIP_DNS_RAND_ID is on

endif

u8_t j,k; for(j = 0; j<DNS_MAX_RAND_ATTEMPT; j++) { bool clash; u16_t r; r = LWIP_RAND(); clash = false; for (k = 0; k < DNS_TABLE_SIZE; ++k) { if( (k != i) && (dns_table[k].state != DNS_STATE_UNUSED) && (dns_table[k].queryID == r) ) { clash = true; break; } } / we found an unused ID / if(!clash) return r; }

LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("Too many clashin random IDs\n", ));

/ could not find a unique random number / / either bad luck, or broken rand function / / use sequence number instead / return dns_table[i].seqno;

else

/ If not using random numbers, the / / sequence number is better than nothing / return dns_table[i].seqno;

endif

}

Once I put the inner loop in it crashes. It seems to be a non local crash as the message says its working on a function elsewhere at the time.

I got this to compile by breaking out the inner loop into its own function, and then calling that via a global or volatile function pointer. That was the only way I could find to break the death grip your optimiser had on the inner loop.

/**

static bool check_rand(u16_t r, int i) { u8_t j; for (j = 0; j < DNS_TABLE_SIZE; ++j) { if( (j != i) && (dns_table[j].state != DNS_STATE_UNUSED) && (dns_table[j].queryID == r) ) { return false; } } / no clashes, its good / return true; }

/*

/**

typedef bool (*check_fn)(u16_t r, int i); static volatile check_fn rand_check = check_rand;

static u16_t new_query_id(int i) {

if LWIP_DNS_RAND_ID

if !defined(LWIP_RAND)

error "LWIP_RAND must be specified if LWIP_DNS_RAND_ID is on"

endif

u8_t j;

for(j = 0; j<DNS_MAX_RAND_ATTEMPT; j++) { u16_t r; r = LWIP_RAND(); / This used to be a nested loop, but it crashed llvm / if((rand_check)(r, i)) { / we found an unused ID */ return r; } }

LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("Too many clashin random IDs\n", ));

/ could not find a unique random number / / either bad luck, or broken rand function / / use sequence number instead /

endif

/ If not using random numbers, the / / sequence number is better than nothing / return dns_table[i].seqno; }

llvmbot commented 10 years ago

I've found the line which seems to cause the crash.

In the code below, adding the "pEntry->queryID = new_query_id(i);" line seems to do it. BTW, the code is from LWIP: http://savannah.nongnu.org/projects/lwip/

static void dns_check_entry(u8_t i) { err_t err; struct dns_table_entry *pEntry = &dns_table[i];

LWIP_ASSERT("array index out of bounds", i < DNS_TABLE_SIZE);

switch(pEntry->state) {

case DNS_STATE_NEW: {
  /* initialize new entry */
  pEntry->state   = DNS_STATE_ASKING;
  pEntry->numdns  = 0;
  pEntry->tmr     = 1;
  pEntry->retries = 0;
  //pEntry->queryID  = new_query_id(i);

  /* send DNS packet for this entry */
  err = dns_send(pEntry->numdns, pEntry->name, pEntry->queryID);
  if (err != ERR_OK) {
    LWIP_DEBUGF(DNS_DEBUG | LWIP_DBG_LEVEL_WARNING,
                ("dns_send returned error: %s\n", lwip_strerr(err)));
  }
  break;
}
Endilll commented 1 year ago

Can't reproduce using Clang 3.2 through 3.4 with assertions enabled. It should be noted that those versions don't recognize -arm-dont-use-movt and -lowregs-stack-align. Given that you're using Apple Clang, this might be a downstream issue.