섹션 배치와 크기 정렬을 위해 수정한 링커 스크립트가 있는데, 이 책 자체가 윈도우를 기준으로 설명하고 있어서 맥 사용자인 나와는 좀 다르다.
일단 맥에서는 32비트용 링커 스크립트가 어디에 저장되어있는지 확인해보자.
명령어 오류
gcc -melf_i386 -T elf_i386.x -nostdlib Main.o -o Main.elf
위 명령어가 오류가 난다. 확인중
오류 메시지: unknown argument: '-melf_i386'
gcc -m32 -T elf_i386.x -nostdlib Main.o -o Main.elf 이 명령어로 대체할 수 있다. 책에서는 똑같은 설명인데 옵션을 앞에서는 -m32로 주고 뒤에서는 -melf_i386으로 주었다.
그다음오류
ld: unknown option: -T
[220817]
왠지 내가 또 명령어를 맘대로 바꿔서 그런것 같다.
사실 책에는 gcc가 아니라 x86_64-pc-linux-ld.exe로 진행중이다. 찾아보자.
[220821]
gcc use linker script command - Google 검색
The INPUT command directs the linker to include the named files in the link, as though they were named on the command line. For example, if you always want to ...
www.google.com
책에서 -T 옵션은 내가 만든 커스텀 링커 스크립트를 이용해서 링크를 수행하라는 옵션이라고 한다.
그래서 gcc use linker script command라고 검색했다.
http://korea.gnu.org/manual/release/ld/ld-mahajjh/ld_3.html#SEC6
Using LD, the GNU linker - Linker Scripts
Every link is controlled by a linker script. This script is written in the linker command language. 모든 링크 과정은 링커 스크립트가 조정한다. 이 스크립트는 링커 명령 언어로 쓰여진다. The main purpose of the linker script
korea.gnu.org
You may supply your own linker script by using the `-T' command line option. When you do this, your linker script will replace the default linker script.
gnu 설명에도 이게 있는데 왜 안되지..? 애초에 명령어가 gcc로 하면 안되는 건가 싶다.
그래서 use ld in mac으로 검색
https://stackoverflow.com/questions/32531799/ld-command-on-osx
ld command on OSX
I wanted to use a Dynamic shared library ".so" file using ld command on Mac OS X. I'm able to compile without errors and create the file using ld -dynamic -dylib -arch x86_64 -macosx_version_min ...
stackoverflow.com
변경한 명령어
ld -dynamic -dylib -arch i386 Main.o -o Main.elf
인데 이제 warning은 뜨지만 파일이 생성되긴 한다. 이제 커스텀으로 만든 링커 스크립트를 통해서 Object 파일을 링크해보자.
참고:
https://www.real-world-systems.com/docs/ld.1.html
ld mac os linker
-flat_namespace Alters how symbols are resolved at build time and runtime. With -two_levelnamespace (the default), the linker only searches dylibs on the command line for symbols, and records in which dylib they were found. With -flat_namespace, the linker
www.real-world-systems.com
https://forum.osdev.org/viewtopic.php?t=19339
OSDev.org • View topic - ld: unknown option: -T
berkus wrote: Looks like quite a good task to weed out people who cannot solve basic problems, ain't it? Check configure output, it might tell you WHY binutils decides not to build ld. Run make in ld directory alone and note any errors. Check make install
forum.osdev.org
위와 같은 글을 보았고, 크로스 컴파일 프로그램으로 다시 검색해봐야겠다.
애플 ls는 크로스 컴파일 안됨
https://github.com/jart/cosmopolitan/issues/80
Apple's linker can't build portable binaries · Issue #80 · jart/cosmopolitan
Trying the example on macOS Catalina 10.15.7: $ gcc -g -O -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone -o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds -include cosmopolitan.h crt...
github.com
그래서 이걸 찾음
https://formulae.brew.sh/formula/x86_64-elf-gcc#default
x86_64-elf-gcc
Homebrew’s package index
formulae.brew.sh
설치 후 오브젝트 파일을 생성하려고 했는데 또 오류가 난다.
cannot find crt0.o: No such file or directory
[220916]
스택오버플로우에서 찾아보는중..
https://stackoverflow.com/questions/41640978/cannot-find-crt0-o-no-such-file-or-directory
cannot find crt0.o: No such file or directory
I'm trying to learn operation system using i386-elf-gcc on my mac pro. Os version is Sierra. I use Macports to install the compile environment by typing sudo port install i386-elf-gcc in bash. But ...
stackoverflow.com
맥에서 돌아가는 ld를 다시 설치해보자.
https://stackoverflow.com/questions/39059597/how-to-create-an-elf-executable-on-mac-os-x
How to create an ELF executable on Mac OS X?
I'm following this tutorial: https://littleosbook.github.io/#linking-the-kernel and I'm on a Mac. I'm at the point where I have an object file created from nasm, and I want to turn it into an ELF
stackoverflow.com
와 드디어 elf 파일이 나왔다...
위에서 마지막 덧글을 토대로 설치를 하고, 명령어 ` ~/.local/binutils/bin/i386-unknown-linux-gnu-ld -T ./01.Kernel32/elf_i386.x Main.o -o Main.elf`
나머지는 책을 진행하니까 쭉 진행되었다. 나중에 다시 정리하자...
'개발일지' 카테고리의 다른 글
[OS개발] 10. 64비트 모드로 전환하자 (0) | 2022.10.03 |
---|---|
[OS개발] 5. 32비트 보호 모드로 전환 - 정리중 (0) | 2022.08.08 |
[OS개발] 4.플로피 디스크에서 OS 이미지 로딩 (0) | 2022.08.02 |
[OS개발] 3. 부트로더 만들기 (0) | 2022.08.01 |
[OS개발] 2. 64비트 프로세서 (0) | 2022.07.31 |