3 #----------------------------------------------------------------------------
4 # We must avoid using the vanilla new/new[] operators (and consequently, the
5 # vanilla delete/delete[] operators) in SpiderMonkey, see bug 624878 for why.
8 # - Detects if any of the vanilla new/new[] operators are used in a file.
9 # Its exit code is 1 if it found some, and 0 if it didn't.
10 # - Doesn't detect delete/delete[] because it appears they can be present
11 # somehow due to virtual destructors, but this is ok because vanilla
12 # delete/delete[] calls don't make sense without corresponding new/new[]
13 # calls, and any explicit calls will be caught by Valgrind's mismatched
14 # alloc/free checking.
15 # - Doesn't detect the 'nothrow' variants, which are ok but probably still
17 # - Is designed to only run on Linux (though it may also work on Mac); one
18 # platform will be enough to catch any violations.
20 # If this script fails:
21 # - You need to find the uses of vanilla new/delete and replace them with
22 # js_new()/js_delete().
23 # - Run this script on each of the .o files, that should narrow it down.
24 # - After that, one way to find them is to run 'objdump -r -C' on the
25 # relevant .o files. For example, you might search for 'operator new' and
26 # find a record like this:
28 # RELOCATION RECORDS FOR [.text._ZN3JSC14ExecutablePool6createEj]:
30 # 00000009 R_386_PC32 __i686.get_pc_thunk.bx
31 # 0000000f R_386_GOTPC _GLOBAL_OFFSET_TABLE_
32 # 0000001b R_386_PLT32 operator new(unsigned int)
33 # 0000002e R_386_PC32 JSC::ExecutablePool::ExecutablePool(unsigned int)
34 # 0000004a R_386_PC32 JSC::ExecutablePool::~ExecutablePool()
35 # 00000052 R_386_PLT32 operator delete(void*)
37 # This says that vanilla 'new' and 'delete' are both used in
38 # JSC::ExecutablePool::create(unsigned int). This doesn't always work,
39 # though. (Nb: use 'c++filt' to demangle names like
40 # _ZN3JSC14ExecutablePool6createEj.)
42 # If that doesn't work, use grep.
43 #----------------------------------------------------------------------------
46 echo "usage: find_vanilla_new_calls <file>"
52 if [ ! -f $file ] ; then
53 echo "TEST-UNEXPECTED-FAIL | find_vanilla_new_calls | file '$file' not found"
59 nm -C $file > $tmpfile1
61 # Need to double-escape '[' and ']' to stop grep from interpreting them
63 grep 'operator new(unsigned int)' $tmpfile1 >> $tmpfile2
64 grep 'operator new(unsigned long)' $tmpfile1 >> $tmpfile2
65 grep 'operator new\\[\\](unsigned int)' $tmpfile1 >> $tmpfile2
66 grep 'operator new\\[\\](unsigned long)' $tmpfile1 >> $tmpfile2
69 if [ -s $tmpfile2 ] ; then
70 echo "TEST-UNEXPECTED-FAIL | find_vanilla_new_calls | found calls are listed below"
77 echo "TEST-PASS | find_vanilla_new_calls | ok"