为什么gcc编译出来的ELF文件是“shared object”格式

软件和网站开发以及相关技术探讨
回复
头像
jiandan23
帖子: 86
注册时间: 2010-12-17 22:31
系统: Mint 19.2

为什么gcc编译出来的ELF文件是“shared object”格式

#1

帖子 jiandan23 » 2023-01-31 11:14

如果是Mint19.2系统(对应Ubuntu 18.04):
user@mint19:~$ cat hello.c
#include<stdio.h>
int main(){
printf("hello!\n");
return 0;
}
user@mint19:~$ gcc -o hello hello.c
user@mint19:~$ ./hello
hello!
user@mint19:~$ file hello
hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=5b58c0bfb8b27791cf9c628c861e613a41b0bca7, not stripped
如果是Mint21.1系统(对应Ubuntu 22.04):
user@mint21:~$ cat hello.c
#include<stdio.h>
int main(){
printf("hello!\n");
return 0;
}
user@mint21:~$ gcc -o hello hello.c
user@mint21:~$ ./hello
hello!
user@mint21:~$ file hello
hello: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=9b3d52481c82082ae41d7596191ffb3e8d941c98, for GNU/Linux 3.2.0, not stripped
为什么会有这种不同,这个是在哪里设置的?
onlylove
论坛版主
帖子: 5233
注册时间: 2007-01-14 16:23

Re: 为什么gcc编译出来的ELF文件是“shared object”格式

#2

帖子 onlylove » 2023-01-31 12:10

之前哪个版本的gcc的默认设置不一样好像?需要加个参数还是咋回事来着,忘了(之前遇到过一次,这里好像也有人问过
头像
astolia
论坛版主
帖子: 6454
注册时间: 2008-09-18 13:11

Re: 为什么gcc编译出来的ELF文件是“shared object”格式

#3

帖子 astolia » 2023-01-31 22:57

onlylove 写了: 2023-01-31 12:10 之前哪个版本的gcc的默认设置不一样好像?需要加个参数还是咋回事来着,忘了(之前遇到过一次,这里好像也有人问过
如果半懂不懂,可以不用强行回答。这个跟gcc参数没关系。
jiandan23 写了: 2023-01-31 11:14 为什么会有这种不同,这个是在哪里设置的?
关于pie,参考 https://forum.ubuntu.com.cn/viewtopic.php?f=77&t=480688
18.04中的file是旧版本,没对用pie编译出的可执行文件和库文件做区分。22.04中的file已经更新过了,能区分这两种情况。
回复