From: Peng Yu <pengyu.ut@gmail.com>
To: "Carlos O'Donell" <carlos@systemhalted.org>
Cc: Jeffrey Walton <noloader@gmail.com>,
libc-help <libc-help@sourceware.org>
Subject: Re: Best reference for understanding ELF format
Date: Tue, 20 Apr 2021 22:19:33 -0500 [thread overview]
Message-ID: <CABrM6wmwO-DdALbDRrbeXBvJh7d8ez1MQKkztyrSPqx+4rYR_g@mail.gmail.com> (raw)
In-Reply-To: <CAE2sS1jHb39bLGtRZuqEaEOGu-HXHB1NxSfoSxPgXQG0VFWcEA@mail.gmail.com>
On Tue, Apr 20, 2021 at 11:51 AM Carlos O'Donell
<carlos@systemhalted.org> wrote:
>
> On Tue, Apr 20, 2021 at 12:39 PM Jeffrey Walton via Libc-help
> <libc-help@sourceware.org> wrote:
> >
> > On Tue, Apr 20, 2021 at 12:29 PM Peng Yu via Libc-help
> > <libc-help@sourceware.org> wrote:
> > > ...
> > > People don't usually directly call ld to generate object, executable
> > > or shared library files.
> > >
> > > Instead, gcc/clang are called. So there is nothing wrong to say those
> > > files are produced by gcc/clang, at least at a superficially level.
> > > You can say that gcc/clang don't directly produce the ELF files.
> > > Nevertheless, this doesn't add too much to the topic of this thread.
> >
> > I think Clang can produce object files directly. Clang has an
> > integrated assembler.
>
> Conceptually the point is the same though.
>
> The compiler relies on an assembler and static linker to generate the
> object files.
>
> Whether that assembler is a library and the invocation is a library
> call, or it's a secondary process via a pipe, the concept being
> discussed is the same.
>
> The compiler itself (language front end,
I think the "front end" is actually the cc1 program which is not
exposed to PATH by default for gcc. In my system, it is the following
one, which transforms a .c file to a .s file.
/usr/lib/gcc/x86_64-linux-gnu/10/cc1
Then the .s file is processed by as, to generate a .o file. Then, the
final a.out file is generated from the .o file by ld.
The command gcc is just a wrapper of the three programs (cc1/as/ld).
The following is a minimal work example that demonstrates this.
$ cat main.c
#include <stdio.h>
int main() {
puts("Hello World!");
return 0;
}
$ /usr/lib/gcc/x86_64-linux-gnu/10/cc1 -quiet main.c -o main.s
$ as -o main.o main.s
$ ld -dynamic-linker /lib64/ld-linux-x86-64.so.2
/usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o
/usr/lib/x86_64-linux-gnu/crtn.o main.o -lc
> or driver) doesn't produce
> ELF format object files. Technical clarity around these distinctions
> helps at a later stage when we're trying to explain other concepts
> where the distinction matters or where the distinction is muddled e.g.
> LTO, ThinLTO etc.
As these (LTO, ThinLTO) specific to the llvm pipeline?
--
Regards,
Peng
next prev parent reply other threads:[~2021-04-21 3:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-16 3:38 Peng Yu
2021-04-16 3:47 ` Mike Frysinger
2021-04-17 12:31 ` Peng Yu
2021-04-19 7:29 ` Szabolcs Nagy
2021-04-19 7:53 ` Florian Weimer
2021-04-20 1:58 ` Peng Yu
2021-04-20 7:08 ` tomas
2021-04-20 13:19 ` Mike Frysinger
2021-04-20 13:40 ` Peng Yu
2021-04-20 14:18 ` Mike Frysinger
2021-04-20 15:12 ` Peng Yu
2021-04-20 16:39 ` Jeffrey Walton
2021-04-20 16:51 ` Carlos O'Donell
2021-04-21 3:19 ` Peng Yu [this message]
2021-04-20 17:55 ` Mike Frysinger
2021-04-20 18:01 ` Mike Frysinger
2021-04-20 8:14 ` Jeffrey Walton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABrM6wmwO-DdALbDRrbeXBvJh7d8ez1MQKkztyrSPqx+4rYR_g@mail.gmail.com \
--to=pengyu.ut@gmail.com \
--cc=carlos@systemhalted.org \
--cc=libc-help@sourceware.org \
--cc=noloader@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).