環境
-bash-3.00# uname -a SunOS solaris101 5.10 Generic_142910-17 i86pc i386 i86pc -bash-3.00# cat /etc/release Oracle Solaris 10 9/10 s10x_u9wos_14a X86 Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. Assembled 11 August 2010 -bash-3.00# isainfo -v 64-bit amd64 applications ssse3 mon sse3 sse2 sse fxsr mmx cmov amd_sysc cx8 tsc fpu 32-bit i386 applications ssse3 mon sse3 sse2 sse fxsr mmx cmov sep cx8 tsc fpu
現象
- 32bitの共有ライブラリを LD_PRELOAD 環境変数に設定する。
-bash-3.00$ file /lib/32/libc.so /lib/32/libc.so: ELF 32-bit LSB dynamic lib 80386 Version 1 [SSE MMX CMOV SEP FPU], dynamically linked, not stripped, no debugging information available -bash-3.00$ export LD_PRELOAD=/lib/32/libc.so
- ls コマンドを実行してみる。
-bash-3.00$ ls
Desktop Documents core db.rsp response software
- sort コマンドを実行してみる。
-bash-3.00$ sort ld.so.1: sort: fatal: /lib/32/libc.so: wrong ELF class: ELFCLASS32 Killed -bash-3.00$ file `which sort` /usr/bin/sort: ELF 32-bit LSB executable 80386 Version 1, dynamically linked, stripped
- sqlplus を実行してみる。
-bash-3.00$ sqlplus / as sysdba
ld.so.1: sqlplus: fatal: /lib/32/libc.so: wrong ELF class: ELFCLASS32
Killed
想定原因
LD_PRELAD を使用すると他のOSコマンドでエラーが発生する理由
- LD_PRELOAD を使用すると、32bit、64bitのいずれの実行バイナリを実行する場合も、32bit の共有ライブラリをプリロードするため。
- 32bitの実行バイナリを実行する際は問題ないが64bitのプログラムを実行する際にエラー(ld.so.1: sqlplus: fatal: ... : wrong ELF class: ELFCLASS32)が発生する。
LD_PRELAD_32 を使用すると他のOSコマンドでエラーが発生しない理由
- LD_PRELOAD_32 を使用すると、32bitのプログラムを実行する場合のみ32bit の共有ライブラリをプリロードするため32bit、64bitのいずれの実行バイナリを実行しても問題ない。
参考情報
Environment Variables
http://download.oracle.com/docs/cd/E19253-01/816-5165/6mbb0m9jg/index.html
Each environment variable can be specified with a _32 or _64 suffix.
This makes the environment variable specific, respectively, to 32 bit or 64 bit processes.
(中略)
LD_PRELOAD, LD_PRELOAD_32, and LD_PRELOAD_64 Provides a list of shared objects, separated by spaces. These objects are loaded after the program being executed but before any other shared objects that the program references. Symbol definitions provided by the preloaded objects interpose on references made by the shared objects that the program references.
Symbol definitions provided by the preloaded objects do not interpose on the symbol definitions provided by the program.
対処
- 32bitの共有ライブラリを LD_PRELOAD_32 環境変数に設定する。
-bash-3.00$ export LD_PRELOAD_32=/lib/32/libc.so
- ls コマンドを実行する。
-bash-3.00$ ls Desktop Documents core db.rsp response software -sortコマンドを実行してみる。 >|sh| -bash-3.00$ ls |sort Desktop Documents core db.rsp response software
- sqlplus を実行してみる。
-bash-3.00$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.2.0 Production on Fri Feb 4 20:06:35 2011 Copyright (c) 1982, 2010, Oracle. All rights reserved. Connected to an idle instance. SQL> exit Disconnected