MIPS環境でPostgreSQLがコンパイルできない
概要
Bug #88344を参照してください。
パッチ
回避策としてのパッチを提出済み。CFLAGSを"-O0 -pipe"にするパッチの方が安全な気はする。
調査対象ハードウェア
- O2(ip32)
- Octane(ip30)
調査結果
次の最適化オプションを無効にする事で動作するPostgreSQLを作成する事ができる。
- -funit-at-a-time
- 最適化フラグ-O2で有効になる。これを無効にしないと、tasが解決できないというエラーが出てコンパイルできない。
- -fmerge-constants
- 最適化フラグ-O1で有効になる。これを無効にしないと、initdbでSegmentation faultが発生して終了する。
調査
- gcc-3.3.x環境下ではこの問題は発生しないようだ。
- gcc-3.4.1-r3でコンパイルした場合も同様にこの問題が発生する。gcc-3.4.x系に関係するバグの可能性大。
- 最適化を-O1に落とす事でコンパイルは成功。initdbで失敗。
- 最適化を-O0に落とす事でコンパイル・initdbが成功。gccの最適化フラグを一部無効にすることでうまくいくのではないかと推測。
- CFLAGSに-fno-unit-at-a-timeを追加。コンパイル成功。initdbはSegFaultを起こして実行できず。
- CFLAGSに-O1で有効になる最適化を無効にするフラグを追加(-fno-unit-at-a-timeはコンパイルを成功させるために必要)。コンパイル成功。initdbも動作する。
- -O1で有効になる最適化を徐々に無効にして問題の最適化を割り出す。結果、-fmerge-constantsを無効にする事でinitdbが動作する事が判明。
作業ログ
-O2 -mips4 -mabi=32 -fomit-frame-pointer
バグで報告された内容と同じエラーメッセージ
-O1 -mips4 -mabi=32 -fomit-frame-pointer
ちなみに、下記エラーはCFLAGSに-fno-merge-constantsを追加する事で発生しなくなる。
ebuild /var/db/pkg/dev-db/postgresql-7.4.7-r1/postgresql-7.4.7-r1.ebuild config * Creating the data directory ... * Initializing the database ... The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale C. fixing permissions on existing directory /var/lib/postgresql/data... ok creating directory /var/lib/postgresql/data/base... ok creating directory /var/lib/postgresql/data/global... ok creating directory /var/lib/postgresql/data/pg_xlog... ok creating directory /var/lib/postgresql/data/pg_clog... ok selecting default max_connections... 10 selecting default shared_buffers... 50 creating configuration files... ok creating template1 database in /var/lib/postgresql/data/base/1... FATAL: INTO is only allowed on first SELECT of UNION/INTERSECT/EXCEPT sed: couldn't write 77 items to stdout: Broken pipe cat: write error: Broken pipe initdb: failed * If you are upgrading from a pre-7.3 version of PostgreSQL, please read * the README.adddepend file for information on how to properly migrate * all serial columns, unique keys and foreign keys to this version.
-O0 -mips4 -mabi=32 -fomit-frame-pointer
# su postgres -c "/usr/bin/initdb --pgdata /tmp/hoge"
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale C.
creating directory /tmp/hoge... ok
creating directory /tmp/hoge/base... ok
creating directory /tmp/hoge/global... ok
creating directory /tmp/hoge/pg_xlog... ok
creating directory /tmp/hoge/pg_clog... ok
selecting default max_connections... 100
selecting default shared_buffers... 1000
creating configuration files... ok
creating template1 database in /tmp/hoge/base/1... ok
initializing pg_shadow... ok
enabling unlimited row size for system tables... ok
initializing pg_depend... ok
creating system views... ok
loading pg_description... ok
creating conversions... ok
setting privileges on built-in objects... ok
creating information schema... ok
vacuuming database template1... ok
copying template1 to template0... ok
Success. You can now start the database server using:
/etc/init.d/postgresql start
-O2 -mips4 -mabi=32 -fomit-frame-pointer -fno-unit-at-a-time
# su postgres -c "/usr/bin/initdb --pgdata /tmp/hoge" The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale C. creating directory /tmp/hoge... ok creating directory /tmp/hoge/base... ok creating directory /tmp/hoge/global... ok creating directory /tmp/hoge/pg_xlog... ok creating directory /tmp/hoge/pg_clog... ok selecting default max_connections... /usr/bin/initdb: line 572: 30037 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 572: 30039 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 572: 30041 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 572: 30043 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 572: 30045 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 572: 30047 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 10 selecting default shared_buffers... /usr/bin/initdb: line 585: 30048 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30049 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30050 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30051 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30052 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30053 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30054 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30055 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30056 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30057 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 /usr/bin/initdb: line 585: 30058 Segmentation fault "$PGPATH"/postgres -boot -x0 $TEST_OPT template1 </dev/null >/dev/null 2>&1 50 creating configuration files... ok creating template1 database in /tmp/hoge/base/1... /usr/bin/initdb: line 644: 30134 Segmentation fault "$PGPATH"/postgres -boot -x1 $PGSQL_OPT $BOOTSTRAP_TALK_ARG template1 initdb: failed initdb: removing data directory "/tmp/hoge"