homebrew ã« x86_64-elf-gcc ããããã¨ã«æ°ã¥ãã¦ãã®ã§è§¦ã£ã¦ã¿ããã¨ã«ãã¾ããã
$ brew info x86_64-elf-gcc x86_64-elf-gcc: stable 10.2.0 (bottled) The GNU compiler collection for x86_64-elf https://gcc.gnu.org /usr/local/Cellar/x86_64-elf-gcc/10.2.0 (584 files, 122MB) * Poured from bottle on 2020-08-03 at 07:35:56 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/x86_64-elf-gcc.rb ==> Dependencies Required: gmp â, libmpc â, mpfr â, x86_64-elf-binutils â $
ã¨ãããã Hello, world!
ãããã¨ã«ãã¾ãã
$ cat main.c int main() { printf("Hello, world!\n"); } $ x86_64-elf-gcc main.c main.c:1:10: fatal error: stdio.h: No such file or directory 1 | #include <stdio.h> | ^~~~~~~~~ compilation terminated. $
ããããã¡ã¤ã«ãè¦å½ãããªããããåããäºå®ã®ç°å¢ (Ubuntu 20.04.1 LTS) ã®ããã±ã¼ã¸ããå¼ã£ãæããã¨ã«ãã¾ãã
$ wget http://mirrors.kernel.org/ubuntu/pool/main/g/glibc/libc6-dev_2.31-0ubuntu9_amd64.deb $ dpkg -x libc6-dev_2.31-0ubuntu9_amd64.deb ${HOME}/sys-root/ubuntu $
ã¤ã³ã¯ã«ã¼ããã¹ã追å ãã¦ãåã³ã³ãã¤ã«ãã¦ã¿ã¾ãã
$ x86_64-elf-gcc main.c -I ${HOME}/sys-root/ubuntu/usr/include -I ${HOME}/sys-root/ubuntu/usr/include/x86_64-linux-gnu /usr/local/opt/x86_64-elf-binutils/bin/x86_64-elf-ld: cannot find crt0.o: No such file or directory /usr/local/opt/x86_64-elf-binutils/bin/x86_64-elf-ld: cannot find -lc collect2: error: ld returned 1 exit status $
ã³ã³ãã¤ã«ã¯ã§ãã¾ããããªã³ã¯ã§ããã¾ãã
libc6-devel ã«ã¯ãããã
crt0.o
ãå
¥ã£ã¦ããªãããã§ãã
ä¸å¿ãçæããããªãã¸ã§ã¯ãã ELF ãã©ããã確èªãã¦ããã¾ãã
$ x86_64-elf-gcc main.c -I ${HOME}/sys-root/ubuntu/usr/include -I ${HOME}/sys-root/ubuntu/usr/include/x86_64-linux-gnu -c $ file main.o main.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped $
ç¶ã㯠ubuntu å´ã§ãã£ã¦ã¿ã¾ãã(scp ãªã©ã§é©å½ã«ã³ãã¼ãã¾ã)
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS" $ gcc main.o /usr/bin/ld: main.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE collect2: error: ld returned 1 exit status $
mac å´ã§ -fPIE
ãã¤ãã¦ã³ã³ãã¤ã«ããªããããããå度 ubuntu å´ã«æã£ã¦ããã¾ãã
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS" $ gcc main.o $ ./a.out Hello, world! $
ãªã³ã¯ã¾ã§ããããå ´åã¯èªå㧠gcc ãã³ã³ãã¤ã«ããå¿ è¦ãããããã§ãã