【未完】armv7lマシンでmongodbを導入しようとしてこけたときのメモ

#### 前提
ubuntu 18.04
CPUがarmv7l

#### ことの始まり
aptでmongodb入れようとしても全然入らない

#### 気づいた
mongodbは32bitサポートしてない

#### 検索した
mongodbのソースを自分でコンパイルするといいらしい
https://www.javaer101.com/ja/article/1941494.html

#### コンパイルエラーが出る
```
scons: building `build/opt/mongo/scripting/mozjs/base.o' because it doesn't exist
Compiling build/opt/mongo/scripting/mozjs/base.o
cc1plus: fatal error: js-config.h: No such file or directory
compilation terminated.
scons: *** [build/opt/mongo/scripting/mozjs/base.o] Error 1
```

#### js-config.hは無いのか？
ある

```
./mozjs-38/platform/x86_64/solaris/include/js-config.h
./mozjs-38/platform/x86_64/openbsd/include/js-config.h
./mozjs-38/platform/x86_64/windows/include/js-config.h
./mozjs-38/platform/x86_64/linux/include/js-config.h
./mozjs-38/platform/x86_64/osx/include/js-config.h
./mozjs-38/platform/x86_64/freebsd/include/js-config.h
./mozjs-38/platform/i386/openbsd/include/js-config.h
./mozjs-38/platform/i386/windows/include/js-config.h
./mozjs-38/platform/i386/linux/include/js-config.h
./mozjs-38/platform/ppc64le/linux/include/js-config.h
./mozjs-38/platform/arm64/linux/include/js-config.h
```

#### SConscriptをみてみると
環境変数でインクルードファイルの場所を決めていた

```
    thirdPartyIncludePathList.append(
        ('mozjs', ['#/src/third_party/mozjs' + mozjsSuffix + '/include',
                   '#/src/third_party/mozjs' + mozjsSuffix + '/mongo_sources',
                   '#/src/third_party/mozjs' + mozjsSuffix + '/platform/' + env["TARGET_ARCH"] + "/" + env["TARGET_OS"] + "/include",
        ]))
```

なので```env["TARGET_ARCH"] + "/" + env["TARGET_OS"]``` を出力してみた。
そうすると出力されたのは```arm/linux```

なるほど、armで32bitを想定しておらず環境変数で相対パス作ったら存在しないディレクトリ見に行っていたと言うことっぽい。
なので```/mozjs-38/platform/arm64/linux/include/*```を```/mozjs-38/platform/arm/linux/include/*```に移動

#### コンパイルエラー
```
Compiling build/opt/third_party/wiredtiger/src/async/async_api.o
In file included from src/third_party/wiredtiger/src/include/wt_internal.h:305:0,
                 from src/third_party/wiredtiger/src/async/async_api.c:9:
src/third_party/wiredtiger/src/include/gcc.h:235:2: error: #error "No write barrier implementation for this hardware"
 #error "No write barrier implementation for this hardware"
  ^~~~~
In file included from src/third_party/wiredtiger/src/include/wt_internal.h:350:0,
                 from src/third_party/wiredtiger/src/async/async_api.c:9:
src/third_party/wiredtiger/src/include/verify_build.h: In function '__wt_verify_build':
src/third_party/wiredtiger/src/include/verify_build.h:40:7: error: size of array '__check_WT_REF' is negative
  char __check_##type[1 - 2 * !(sizeof(type) == (e))];  \
       ^
src/third_party/wiredtiger/src/include/verify_build.h:57:2: note: in expansion of macro 'SIZE_CHECK'
  SIZE_CHECK(WT_REF, WT_REF_SIZE);
  ^~~~~~~~~~
src/third_party/wiredtiger/src/include/verify_build.h:37:49: error: size of unnamed array is negative
 #define WT_STATIC_ASSERT(cond) (void)sizeof(char[1 - 2 * !(cond)])
                                                 ^
src/third_party/wiredtiger/src/include/verify_build.h:63:2: note: in expansion of macro 'WT_STATIC_ASSERT'
  WT_STATIC_ASSERT(sizeof(size_t) >= 8);
  ^~~~~~~~~~~~~~~~
In file included from src/third_party/wiredtiger/src/include/wt_internal.h:359:0,
                 from src/third_party/wiredtiger/src/async/async_api.c:9:
src/third_party/wiredtiger/src/include/mutex.i: In function '__wt_fair_lock':
src/third_party/wiredtiger/src/include/mutex.i:304:4: warning: implicit declaration of function 'WT_PAUSE'; did you mean 'WT_UNUSED'? [-Wimplicit-function-declaration]
    WT_PAUSE();
    ^~~~~~~~
    WT_UNUSED
src/third_party/wiredtiger/src/include/mutex.i:313:2: warning: implicit declaration of function 'WT_READ_BARRIER'; did you mean 'WT_READ_PREV'? [-Wimplicit-function-declaration]
  WT_READ_BARRIER();
  ^~~~~~~~~~~~~~~
  WT_READ_PREV
src/third_party/wiredtiger/src/include/mutex.i: In function '__wt_fair_unlock':
src/third_party/wiredtiger/src/include/mutex.i:331:2: warning: implicit declaration of function 'WT_WRITE_BARRIER'; did you mean 'WT_WITH_BTREE'? [-Wimplicit-function-declaration]
  WT_WRITE_BARRIER();
  ^~~~~~~~~~~~~~~~
  WT_WITH_BTREE
In file included from src/third_party/wiredtiger/src/include/wt_internal.h:363:0,
                 from src/third_party/wiredtiger/src/async/async_api.c:9:
src/third_party/wiredtiger/src/include/btree.i: In function '__wt_page_modify_set':
src/third_party/wiredtiger/src/include/btree.i:433:3: warning: implicit declaration of function 'WT_FULL_BARRIER'; did you mean 'WT_BARRIER'? [-Wimplicit-function-declaration]
   WT_FULL_BARRIER();
   ^~~~~~~~~~~~~~~
   WT_BARRIER
src/third_party/wiredtiger/src/include/btree.i: In function '__wt_ref_key':
src/third_party/wiredtiger/src/include/btree.i:536:39: warning: right shift count >= width of type [-Wshift-count-overflow]
 #define WT_IK_DECODE_KEY_LEN(v)  ((v) >> 32)
                                       ^
src/third_party/wiredtiger/src/include/btree.i:543:12: note: in expansion of macro 'WT_IK_DECODE_KEY_LEN'
   *sizep = WT_IK_DECODE_KEY_LEN(v);
            ^~~~~~~~~~~~~~~~~~~~
src/third_party/wiredtiger/src/include/btree.i: In function '__wt_ref_key_onpage_set':
src/third_party/wiredtiger/src/include/btree.i:535:50: warning: left shift count >= width of type [-Wshift-count-overflow]
 #define WT_IK_ENCODE_KEY_LEN(v)  ((uintptr_t)(v) << 32)
                                                  ^
src/third_party/wiredtiger/src/include/btree.i:562:6: note: in expansion of macro 'WT_IK_ENCODE_KEY_LEN'
  v = WT_IK_ENCODE_KEY_LEN(unpack->size) |
      ^~~~~~~~~~~~~~~~~~~~
src/third_party/wiredtiger/src/include/btree.i: In function '__wt_row_leaf_key_info':
src/third_party/wiredtiger/src/include/btree.i:672:38: warning: right shift count >= width of type [-Wshift-count-overflow]
 #define WT_K_DECODE_KEY_LEN(v)  ((v) >> 32)
                                      ^
src/third_party/wiredtiger/src/include/btree.i:707:13: note: in expansion of macro 'WT_K_DECODE_KEY_LEN'
    *sizep = WT_K_DECODE_KEY_LEN(v);
             ^~~~~~~~~~~~~~~~~~~
src/third_party/wiredtiger/src/include/btree.i:678:39: warning: right shift count >= width of type [-Wshift-count-overflow]
 #define WT_KV_DECODE_KEY_LEN(v)  ((v) >> 55)
                                       ^
src/third_party/wiredtiger/src/include/btree.i:720:13: note: in expansion of macro 'WT_KV_DECODE_KEY_LEN'
    *sizep = WT_KV_DECODE_KEY_LEN(v);
             ^~~~~~~~~~~~~~~~~~~~
src/third_party/wiredtiger/src/include/btree.i: In function '__wt_row_leaf_key_set':
src/third_party/wiredtiger/src/include/btree.i:671:49: warning: left shift count >= width of type [-Wshift-count-overflow]
 #define WT_K_ENCODE_KEY_LEN(v)  ((uintptr_t)(v) << 32)
                                                 ^
src/third_party/wiredtiger/src/include/btree.i:772:6: note: in expansion of macro 'WT_K_ENCODE_KEY_LEN'
  v = WT_K_ENCODE_KEY_LEN(unpack->size) |
      ^~~~~~~~~~~~~~~~~~~
src/third_party/wiredtiger/src/include/btree.i: In function '__wt_row_leaf_value_set':
src/third_party/wiredtiger/src/include/btree.i:672:38: warning: right shift count >= width of type [-Wshift-count-overflow]
 #define WT_K_DECODE_KEY_LEN(v)  ((v) >> 32)
                                      ^
src/third_party/wiredtiger/src/include/btree.i:796:12: note: in expansion of macro 'WT_K_DECODE_KEY_LEN'
  key_len = WT_K_DECODE_KEY_LEN(v); /* Key length */
            ^~~~~~~~~~~~~~~~~~~
src/third_party/wiredtiger/src/include/btree.i:677:50: warning: left shift count >= width of type [-Wshift-count-overflow]
 #define WT_KV_ENCODE_KEY_LEN(v)  ((uintptr_t)(v) << 55)
                                                  ^
src/third_party/wiredtiger/src/include/btree.i:809:6: note: in expansion of macro 'WT_KV_ENCODE_KEY_LEN'
  v = WT_KV_ENCODE_KEY_LEN(key_len) |
      ^~~~~~~~~~~~~~~~~~~~
src/third_party/wiredtiger/src/include/btree.i:680:51: warning: left shift count >= width of type [-Wshift-count-overflow]
 #define WT_KV_ENCODE_VALUE_LEN(v) ((uintptr_t)(v) << 42)
                                                   ^
src/third_party/wiredtiger/src/include/btree.i:810:6: note: in expansion of macro 'WT_KV_ENCODE_VALUE_LEN'
      WT_KV_ENCODE_VALUE_LEN(unpack->size) |
      ^~~~~~~~~~~~~~~~~~~~~~
scons: *** [build/opt/third_party/wiredtiger/src/async/async_api.o] Error 1
scons: building terminated because of errors.
```


src/third_party/wiredtiger/src/include/gcc.h
をみてみると。なるほどまた32bitの```__arm__```の定義がないパターンね。


```
/* Compile read-write barrier */
#define	WT_BARRIER() __asm__ volatile("" ::: "memory")

#if defined(x86_64) || defined(__x86_64__)
/* Pause instruction to prevent excess processor bus usage */
#define	WT_PAUSE()	__asm__ volatile("pause\n" ::: "memory")
#define	WT_FULL_BARRIER() do {						\
	__asm__ volatile ("mfence" ::: "memory");			\
} while (0)
#define	WT_READ_BARRIER() do {						\
	__asm__ volatile ("lfence" ::: "memory");			\
} while (0)
#define	WT_WRITE_BARRIER() do {						\
	__asm__ volatile ("sfence" ::: "memory");			\
} while (0)

#elif defined(i386) || defined(__i386__)
#define	WT_PAUSE()	__asm__ volatile("pause\n" ::: "memory")
#define	WT_FULL_BARRIER() do {						\
	__asm__ volatile ("lock; addl $0, 0(%%esp)" ::: "memory");	\
} while (0)
#define	WT_READ_BARRIER()	WT_FULL_BARRIER()
#define	WT_WRITE_BARRIER()	WT_FULL_BARRIER()

#elif defined(__PPC64__) || defined(PPC64)
/* ori 0,0,0 is the PPC64 noop instruction */
#define	WT_PAUSE()	__asm__ volatile("ori 0,0,0" ::: "memory")
#define	WT_FULL_BARRIER() do {						\
	__asm__ volatile ("sync" ::: "memory");				\
} while (0)

/* TODO: ISA 2.07 Elemental Memory Barriers would be better,
   specifically mbll, and mbss, but they are not supported by POWER 8 */
#define	WT_READ_BARRIER() do {						\
	__asm__ volatile ("lwsync" ::: "memory");			\
} while (0)
#define	WT_WRITE_BARRIER() do {						\
	__asm__ volatile ("lwsync" ::: "memory");			\
} while (0)

#elif defined(__aarch64__)
#define	WT_PAUSE()	__asm__ volatile("yield" ::: "memory")
#define	WT_FULL_BARRIER() do {						\
	__asm__ volatile ("dsb sy" ::: "memory");			\
} while (0)
#define	WT_READ_BARRIER() do {						\
	__asm__ volatile ("dsb ld" ::: "memory");			\
} while (0)
#define	WT_WRITE_BARRIER() do {						\
	__asm__ volatile ("dsb st" ::: "memory");			\
} while (0)

#elif defined(__s390x__)
#define	WT_PAUSE()	__asm__ volatile("lr 0,0" ::: "memory")
#define	WT_FULL_BARRIER() do {						\
	__asm__ volatile ("bcr 15,0\n" ::: "memory");			\
} while (0)
#define	WT_READ_BARRIER()	WT_FULL_BARRIER()
#define	WT_WRITE_BARRIER()	WT_FULL_BARRIER()

#elif defined(__sparc__)
#define	WT_PAUSE()	__asm__ volatile("rd %%ccr, %%g0" ::: "memory")

#define	WT_FULL_BARRIER() do {						\
	__asm__ volatile ("membar #StoreLoad" ::: "memory");		\
} while (0)

/*
 * On UltraSparc machines, TSO is used, and so there is no need for membar.
 * READ_BARRIER = #LoadLoad, and WRITE_BARRIER = #StoreStore are noop.
 */
#define	WT_READ_BARRIER() do {						\
	__asm__ volatile ("" ::: "memory");				\
} while (0)

#define	WT_WRITE_BARRIER() do {						\
	__asm__ volatile ("" ::: "memory");				\
} while (0)

#else
#error "No write barrier implementation for this hardware"
#endif
```

続くかも