Groups
Sign in
Groups
KOZOS友の会
Conversations
About
Send feedback
Help
【質問】elf.hについて
55 views
Skip to first unread message
さとう
unread,
Mar 24, 2023, 4:37:43 AM
3/24/23
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to KOZOS友の会
初めまして、低レイヤー初心者で、
現在12stepOS本を読み進めております。
同時にリンカーローダー実践開発という書籍も読み始めており、
わからなくなってしまった事がありましたので質問させてください。
お恥ずかしながら相当場違いの質問だと思いますが、申し訳ありません。
elf.hというヘッダーファイルの存在が
あまり理解できておらず、
UNIX環境で、簡単なhelloworldのhello.cを作成し、
> gcc hello.c -o hello
とコンパイルすると、elfの実行形式が出力されると思いますが、
hello.cには#include<elf.h>のように記述していないのに、
elfバイナリが出力されるのはなぜなのでしょうか?
私が勝手に解釈した限りでは、上記のようにelf.hをインクルードすることorされることはなく、
上記のような場面でelf.hはそもそも明示的に使われていない、
elfのヘッダー情報はアセンブラが.oファイルを作成する段階で足している。
という解釈を現在しています。
elf.hが明示的にインクルードされている
/usr/include/link.h
/usr/include/linux/elf-fdpic.h
/usr/include/x86_64-linux-gnu/sys/auxv.h
を見つけましたがここで力尽きてしまいました。
12stepOS本のコミュニティでする質問では無いと理解しておりますが
コミュニティをみつけることができなかったので、場違いと思いながら質問させていただきました。申し訳ありません。
もしお手隙の方がいらっしゃいましたらご教授いただけますと幸いです。
keita
unread,
Mar 24, 2023, 10:41:13 AM
3/24/23
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to KOZOS友の会
さとうさん
回答します。
gccがelf形式で出力するプログラムだからです。
コンパイラはhello.cを元に実行ファイルを生成しますが
どんな形式の実行ファイルを生成するかは、コンパイラの実装に依ります。
hello.cはelf形式で出力するということを意識する必要がありません。
ですのでelf.hをインクルードする必要があるのは例えば ELF形式のバイナリデータを
読み込んで解析する場合等、限られると思います。
2023年3月24日金曜日 17:37:43 UTC+9 さとう:
さとう
unread,
Mar 27, 2023, 1:21:24 AM
3/27/23
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to KOZOS友の会
お忙しい中、
ご回答をしていただきありがとうございました。
2023年3月24日金曜日 23:41:13 UTC+9 keita:
Reply all
Reply to author
Forward
0 new messages