undefined reference to `___mulsi3'

閲覧: 339 回
最初の未読メッセージにスキップ

三輪晋

未読、
2011/12/04 7:54:312011/12/04
To: KOZOS友の会
三輪です。

立て続けにスイマセン orz
アライメントについて教えてください。

[環境]
* Microsoft Windows 7 64bit
* cygwin
* gcc 4.5.3
* binutils 2.22.51.20111013

[現象]
KOZOS のソースを http://kozos.jp/kozos/osbook_03.html からダウンロードしました。

static void thread_intrでmakeエラー https://groups.google.com/forum/#!topic/kozos_tomonokai/Lgiu6oIgYuw
は解決しました。

そのうえで src/08/os を make したところエラーになりました。

>>
rin@kotomi[/home/rin/work/OS/KOZOS/osbook/src/08/os]% make
/usr/local/bin/h8300-elf-gcc -c -Wall -mh -nostdinc -nostdlib -fno-
builtin -I. -Os -DKOZOS kozos.c
kozos.c: In function 'thread_exit':
kozos.c:170:3: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
kozos.c:171:3: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
kozos.c: In function 'softerr_intr':
kozos.c:240:3: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
kozos.c:241:3: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
kozos.c: In function 'kz_sysdown':
kozos.c:299:3: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
/usr/local/bin/h8300-elf-gcc -c -Wall -mh -nostdinc -nostdlib -fno-
builtin -I. -Os -DKOZOS syscall.c
/usr/local/bin/h8300-elf-gcc -c -Wall -mh -nostdinc -nostdlib -fno-
builtin -I. -Os -DKOZOS test08_1.c
test08_1.c: In function 'test08_1_main':
test08_1.c:9:3: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
test08_1.c:12:5: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
test08_1.c:13:5: warning: pointer targets in passing argument 1 of
'gets' differ in signedness [-Wpointer-sign]
lib.h:15:5: note: expected 'unsigned char *' but argument is of type
'char *'
test08_1.c:16:7: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
test08_1.c:17:7: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
test08_1.c:21:7: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
test08_1.c:25:3: warning: pointer targets in passing argument 1 of
'puts' differ in signedness [-Wpointer-sign]
lib.h:14:5: note: expected 'unsigned char *' but argument is of type
'char *'
/usr/local/bin/h8300-elf-gcc startup.o main.o interrupt.o lib.o
serial.o kozos.o syscall.o test08_1.o -o kozos -Wall -mh -nostdinc -
nostdlib -fno-builtin -I. -Os -DKOZOS -static -T ld.scr -L.
kozos.o: In function `.L14':
kozos.c:(.text+0x109): undefined reference to `___mulsi3'
collect2: ld returned 1 exit status
make: *** [kozos] エラー 1
<<


kozos のページに説明があります。

(OS自作本編第3回)Ubuntu,Fedora,Cygwinで動作確認した
http://kozos.jp/kozos/osbook_03.html

>>
リンク時に「undefined reference to `___mulsi3'」というエラーが出る. ... エラーの出たファイル中で利用し
ている構造体にダミーのメンバを追加して, 構造体のサイズを2の階乗(4,8,16,32,64など)にしてください.
<<

また、12ステップ本の p.463 「構造体のパディング」も読みました。

ということで kozos.c の冒頭で定義されているいくつかの構造体なのだと当たりをつけて
メンバー変数のサイズを数えてみました。

>>
typedef struct _kz_context {
uint32 sp; 4バイト
} kz_context;

typedef struct _kz_thread {
struct _kz_thread *next; 4バイト (ポインタ)
char name[THREAD_NAME_SIZE + 1]; 16バイト (1バイト x (15 + 1))
char *stack; 4バイト (ポインタ)

struct {
kz_func_t func; 4バイト (ポインタ)
int argc; 2バイト ←←←←
char **argv; 4バイト (ポインタ)
} init;

struct {
kz_syscall_type_t type; 4バイト (2バイト x 2)
kz_syscall_param_t *param; 4バイト (ポインタ)
} syscall;

kz_context context; 4バイト
} kz_thread;

static struct {
kz_thread *head; 4バイト (ポインタ)
kz_thread *tail; 4バイト (ポインタ)
} readyque;
<<


* struct {} init の int argc までが 6 バイト
* char **argv は 4 バイトなので 8 バイト目から開始しないといけない

と思い、int argc のあとに 2 バイトのダミーを置いてみました。

struct { /* スレッドのスタート・アップ(thread_init())に渡すパラメータ */
kz_func_t func; /* スレッドのメイン関数 */
int argc; /* スレッドのメイン関数に渡す argc */
int dummy; ←←←←
char **argv; /* スレッドのメイン関数に渡す argv */
} init;


が、相変わらず undefined reference to `___mulsi3' のエラーになります。

まったく誤解しているのか、当たりが間違ってるのか
どこをパディングすればよいのでしょうか...

SAKAI Hiroaki

未読、
2011/12/04 8:45:392011/12/04
To: kozos_t...@googlegroups.com、hsa...@saturn.dti.ne.jp
坂井です.

int argc は2バイトですがパディングされるため,dummy相当の領域は
コンパイラが自動的に挿入します.よってdummyの挿入は論理的な変化は無いです.

struct _kz_thread が原因かどうかわかりませんが,アラインメント調整すると
したら,sizeof(struct _kz_thread)がおそらく48バイトですので,構造体の
お尻に

kz_context context;

char dummy[16];
} kz_thread;

のようにしてダミー領域を追加して64バイトにするといいかもしれません.


<842a21cc-59e0-40a8...@p14g2000yqp.googlegroups.com>の記事において
miw...@gmail.comさんは書きました。

三輪晋( Miwa Susumu )

未読、
2011/12/04 9:31:472011/12/04
To: kozos_t...@googlegroups.com
三輪です。

2011年12月4日22:45 SAKAI Hiroaki <hsa...@saturn.dti.ne.jp>:


> int argc は2バイトですがパディングされるため,dummy相当の領域は
> コンパイラが自動的に挿入します.よってdummyの挿入は論理的な変化は無いです.
>
> struct _kz_thread が原因かどうかわかりませんが,アラインメント調整すると
> したら,sizeof(struct _kz_thread)がおそらく48バイトですので,構造体の
> お尻に
>
> kz_context context;
>
> char dummy[16];
> } kz_thread;
>
> のようにしてダミー領域を追加して64バイトにするといいかもしれません.

これでイケました。
ヒャッホゥ


アライメントの理解が不足してるので出直してきます ('A`)

--
みわ

全員に返信
投稿者に返信
転送
新着メール 0 件