Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core_self_tests.c: build with -fno-builtin
The memory tests in core_self_tests.c call the malloc()/calloc() API without doing anything meaningful with the output. It turns out that a clever compiler (read: Clang) will detect this and aggressively optimize the code, to the point that a call to calloc() is removed entirely. Here is a reduced test case for the record: $ cat test.c #include <stdlib.h> int main(int argc, char *argv[]) { return calloc(1000000, 1) ? 1 : 0; } $ clang --target=arm-linux-gnueabihf -Os -c test.c $ llvm-objdump -d test.o test.o: file format ELF32-arm-little Disassembly of section .text: 0000000000000000 main: 0: 01 00 a0 e3 mov r0, #1 4: 1e ff 2f e1 bx lr No call to calloc() in the generated code! As strange as it may seem, this is reportedly a valid behavior for the compiler [1]. This optimization is obviously not wanted for the test that tries to check that allocation of a very large buffer fails in OP-TEE. This commit adds the -fno-builtins flag to the compiler command for that particular source file, thus preventing the optimization and making the test pass. Link: [1] https://bugs.llvm.org/show_bug.cgi?id=37304 Signed-off-by: Jerome Forissier <[email protected]> Reviewed-by: Jens Wiklander <[email protected]>
- Loading branch information