Тёмный

CppCon 2018: Matt Godbolt “The Bits Between the Bits: How We Get to main()” 

CppCon
Подписаться 153 тыс.
Просмотров 177 тыс.
50% 1

CppCon.org
-
Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/Cpp...
-
When you run your C++ code, have you ever considered how the linker, loader, operating system, C and C++ runtime all work so hard to get everything set up for you to start running your code in main()?
In this Linux-focused talk, Matt will talk about how the linker stitches together your code and how that fits in with dynamic linking. He'll touch on debugging issues with the loader, and how ODR violations can manifest themselves. Then he'll take a look at what's going on behind the scenes to get the C runtime up, and then the C++ runtime, along with all the global object constructors - showing more reasons why you shouldn't be using them!
By the end of the talk you should have an understanding of how a bundle of object files are brought together by the linker, along with the relevant runtimes, and then loaded and executed by the operating system.
-
Matt Godbolt, Coinbase
Senior Software Engineer
Matt Godbolt is the creator of the Compiler Explorer website. He is passionate about writing efficient code. He has previously worked at a trading firm, on mobile apps at Google, run his own C++ tools company and spent more than a decade making console games. When he's not hacking on Compiler Explorer, Matt enjoys writing emulators for old 8-bit computer hardware.
-
Videos Filmed & Edited by Bash Films: www.BashFilms.com *-----*
Register Now For CppCon 2022: cppcon.org/reg...
*-----*

Опубликовано:

 

26 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 99   
@Sidelobes
@Sidelobes 3 года назад
Absolutely stellar, top-notch talk! While watching this, I felt scattered pieces of my brain all falling into place and going 'click'. I love how he manages to deliver this in a format that I perceived as quite interactive - a real walkthrough of sorts. I wish I had been able to watch a talk like this at the beginning of my career as a C++ developer.
@xplorethings
@xplorethings 5 лет назад
This topic is great, during my undergrad years, I often wondered about the process myself. Looking back, I think I was almost angry at linker implementers for not making it faster, well, then I went down the rabbit hole and had to change my opinion.
@andreasfett6415
@andreasfett6415 5 лет назад
Great talk. Apart from Matt being a really good speaker this is really a topic every C(++) programmer should know about.
@ulysses_grant
@ulysses_grant 6 месяцев назад
You know the lecture is damn good when it's been 10 minutes of talk and you didn't even notice.
@lorenzo42p
@lorenzo42p 2 года назад
44:44 that is interesting, so clever. the whole presentation is interesting, but this part is something special. the way calls are made to the dynamic linker, it's like built in cache.
@brentjackson6966
@brentjackson6966 2 года назад
Brilliant talk! I'd say it's a great watch for any programmer who writes compiled or assembled code. You don't *need* to know what happens to make your C or C++ code into an executable, or what is in that executable, but you'll be a stronger programmer if you do. I think it's really important to have some grasp of this compile+link process so, if nothing else, you know there's no magic going on beneath the hood.
@phip1611
@phip1611 4 года назад
I really like his talks! Really interesting stuff! CS student from Germany here
@realcundo
@realcundo 5 лет назад
Good talk, looking forward to the part 2. :) I had to delve into these once when tracking down a problem with instantiating Foo and returning a pointer to it in one translation unit and then in another TU doing dynamic_cast which always returned NULL. Turned out both translation units saw a Foo class but each TU had its own instance of type_info (with the same contents.) IIRC dynamic cast compared the pointers to type_infos, not the contents so my Foos were never the same type.
@DatMilu2K
@DatMilu2K 5 лет назад
I thank you very much for your great website and this talk! I have learned a lot about how higher level languages compile into assembly code! Im just a kid who tries to learn everything by myself so it was a great help for me to understand what compilers do!
@acho8387
@acho8387 2 года назад
for 95% of this talk I have no idea what's going on, but it's amazing nonetheless
@kim15742
@kim15742 5 лет назад
Woow, Ozric Tentacles is amazing! Thanks for the tip!
@benoitrousseau4137
@benoitrousseau4137 5 лет назад
This is interesting. I think those linker scripts are a GNU thing. The way global constructor calls are implemented in Visual C++ is similar but involves no script at all, it just uses the fact that link.exe sorts section names alphabetically to sandwich global constructor calls between two boundary sections, and then the bootstrap code invokes all function pointers between those boundary sections.
@williamchamberlain2263
@williamchamberlain2263 5 лет назад
Heresy! Possibly..
@SteveHill3D
@SteveHill3D 5 лет назад
Another brit hand up for the Ozric Tentacles!
@Swampdragon102
@Swampdragon102 2 года назад
Wait his name is Godbolt? I always thought the tool just had a really cool brand name, idk
@markblacket8900
@markblacket8900 Месяц назад
Didn't expect Ozric Tentacles to be mentioned here
@PamirTea
@PamirTea 2 года назад
Great talk
@stephanm.g.2111
@stephanm.g.2111 5 лет назад
Great talk.
@rohithill
@rohithill 5 лет назад
What software is used for presentation?
@MattGodbolt
@MattGodbolt 5 лет назад
I use reveal.js. The entire presentation source is at github.com/mattgodbolt/cppcon-bits-between-bits
@abiiranathan
@abiiranathan 2 дня назад
Legend ✴️ Isn't this the guy of compiler explorer?
@nmihaylove
@nmihaylove 4 года назад
I am compiling the empty example in early May 2020 with gcc 9.3.0 on Ubuntu 20.04 and both C and CPP compile to 16456 bytes.
@jimwinchester339
@jimwinchester339 2 года назад
Best sources I have say BSS = "Block Storage Segment", an old IBM assembler directive used for the exact same purpose (uninitialized data).
@severemaisjuste
@severemaisjuste 4 года назад
Amazing speaker, love the energy and the Archeology metaphor ! That eerie feeling when it feels like reverse-engineering an alien technology gifted to earth :)
@SimonBuchanNz
@SimonBuchanNz 3 года назад
Interesting to see how differently this works from Windows. The Linux dynamic linking in particular seems... bizarre. (Not worse, necessarily, but really weird)
@gajananpatil2838
@gajananpatil2838 5 лет назад
How cool is that ! Is there any followup video on this topic ?
@jaredteaches894
@jaredteaches894 2 года назад
This whole talk is a very brief introduction into computer systems! By far the best book for this is computer systems: a programmers approach! It gives over all of this and more!
@indianbandhu
@indianbandhu 5 лет назад
extremely informative talk...thank you so much!!!
@GeorgeGeorgalis
@GeorgeGeorgalis 9 месяцев назад
53:09 there must be application of this technique in LLM, eg (for CPU w/o GPU...) load from model into cpu cache (or RAM) all the tokens 2 or 3 nodes deeper than context, before evaluation...
@meow75714
@meow75714 3 года назад
beautiful
@CppCon
@CppCon 3 года назад
Thank you! 😊
@mage3690
@mage3690 2 года назад
Make linker faster? This may be the ignorance of youth speaking, but I have never waited on either the linker or compiler to do anything. As a matter of fact, I have sometimes told the compiler to rebuild the entire project instead of updating that one line I edited, on the somewhat naive assumption that what I changed could lead to faster execution because changing that one line could lead to the wonderful, nearly sentient optimizing compiler finally figuring out what I was getting at and subsequently optimizing nearly the entire function away into the ether. I'm sure that compiler writers have thought of that sort of thing so I don't have to do that, but still. We all think we can beat the compiler, until we fail miserably.
@afigegoznaet
@afigegoznaet 5 лет назад
I love this guy
@VictorOrdu
@VictorOrdu 5 лет назад
Does this mean that to REALLY understand C++, knowledge of Assembly Language is required?
@snailnailnailnailnailnails
@snailnailnailnailnailnails 5 лет назад
no
@bjarnestronstrup9122
@bjarnestronstrup9122 5 лет назад
@@ControversialOpinion You see to use C++ you don't, to understand it you sort of have to.
@mattr2238
@mattr2238 4 года назад
If you use GDB to debug, you learn both.
@jonaskoelker
@jonaskoelker 3 года назад
I would say it's always a good idea to understand the layer below you.
@x87-64
@x87-64 2 года назад
To be honest, learning C++ is harder than Assembly
@undeaddutch
@undeaddutch 5 лет назад
Bruce Dickenson has lot of knowlegde!
@Omnifarious0
@Omnifarious0 5 лет назад
In the Linux world, DSOs are all position independent code, so they can be placed at any address in memory.
@henriquealrs
@henriquealrs 3 года назад
48:05 why is it you shouldn't use dynamic libraries in financial industry?
@MattGodbolt
@MattGodbolt 3 года назад
I was probably too strict there. In many cases one chooses not to use dynamic libraries as they can be a barrier to optimization - calling across a SO boundary is more expensive than a regular call, and you lose opportunities for inlining that using static libraries (with LTO information) gives you.
@echosystemd
@echosystemd 5 лет назад
gcc 8.2 give 18k for the first example, using same compile options.
@edwardmacnab354
@edwardmacnab354 2 года назад
The way everybody throws around the words Make , linker , compiler you'd think everybody just knew exactly what they were and how they worked . Now we see that hardly anybody knows , and if we actually do look at it all in a debugger we will soon understand why hardly anybody knows how they work.
@anuragkashyap8026
@anuragkashyap8026 Год назад
It's not that hardly anybody knows , I guess you need to get in a good circle .
@zinyang8213
@zinyang8213 5 лет назад
@ 26:26 5 is the new 6 ;)
@__hannibaalbarca__
@__hannibaalbarca__ Год назад
This is why CS should be mathematics first before starting in Computing
@indi13lli
@indi13lli 5 лет назад
Linker command file?
@stefanheinzmann7319
@stefanheinzmann7319 5 лет назад
Isn't it curious how computer nerds consistently use the wrong words? They use a compiler to translate the source text to a symbolic machine code representation. Then they use an assembler to transcribe that into a binary machine code representation. Finally, the linker is used to compile a list of sections, seperate them between code and data and such, and to assemble all that into an executable file that has the code in the text section. When you finally want to execute this file, the loader reads it into memory and links it with the shared libraries. You couldn't make this up! That's nerds at their best!
@MrSapps
@MrSapps 5 лет назад
It's more due to hysterical raisins
@sanchopansa1950
@sanchopansa1950 5 лет назад
19:30 linker
@sanchopansa1950
@sanchopansa1950 5 лет назад
27:48 symbols
@GeorgeTsiros
@GeorgeTsiros 5 лет назад
main(){} also compiles. It warns about implicit int, but then again, int main() {} compiles without any warning (which imho is worse, because it implicitly returns 0) to the exact same assembly.
@GeorgeTsiros
@GeorgeTsiros 5 лет назад
whose problem is that, anyway
@LunarLambda
@LunarLambda 5 лет назад
main; also compiles
@patto2k358
@patto2k358 2 года назад
Culture is a runtime
@williamchamberlain2263
@williamchamberlain2263 5 лет назад
1:05 - oh yes
@xrafter
@xrafter 4 года назад
So linker is magic? I hate this
@trejohnson7677
@trejohnson7677 2 года назад
Linkers are hardly magic. They’re actually straightforward proggies. Read Linkers and Loaders is all I can say. Read “How to Write Shared Libraries” by Ulrich Drepper. One bang them both. Supplement with actual gdb & glibc manual. When you’re ready for your pilgrimage to mecca crack open the System V ABI supplement, and respective documentation for your processor. No magic, just lots of plaintext.
@richie7425
@richie7425 2 года назад
Embedded programming is the worst. It's like every embedded related company decided we will make our own way of doing things just because we can...
@emiliadaria
@emiliadaria 5 лет назад
I need that shirt.
@niking987
@niking987 5 лет назад
Emilia M i got mine from shop.spreadshirt.fr/includecpp
@persemake6090
@persemake6090 5 лет назад
Terrible shirt, no reason to bring this political shit everywhere. Plus it implies that everyone hasn't been included, which simply is not correct. Only good reason to wear this, is attention from naive college girls. (or trolling :D)
@emiliadaria
@emiliadaria 5 лет назад
@@persemake6090 How is this shirt 'political'? It's simply wholesome. 💖 And it doesn't imply anything, other than Matt wanting everyone to feel nice and welcome. I'm very sorry you do not feel that way.
@persemake6090
@persemake6090 5 лет назад
@@emiliadaria You must be living under a rock, to not recognize 'politicalness'' of this shirt. Also what would you think if he had a shirt saying "I don't rape"? For me it's obvious that you "include" everyone, stating that in a shirt, is just suspicious, and implies either that wearer doesn't actually think what the message says on the shirt, or that he thinks that others don't think that, so he needs to "educate " them, or that he just wants to virtue signal to stupid people.
@chrisparker9672
@chrisparker9672 5 лет назад
"White male programmer proclaims social problems have all been fixed. News at 11."
@anon_y_mousse
@anon_y_mousse 2 года назад
Even though I already knew most of this, it was fun. I just wish Brit's would stop intentionally mispronouncing so many words as well as pronouncing abbreviations that don't really form pronounceable words. For instance, xor is an abbreviation of eXclusive OR, so you should say X-OR, and the char type in C and by extension in C++ is an abbreviation for character, so it should be pronounced like care and not the fire adjacent form.
@yaroslavpanych2067
@yaroslavpanych2067 5 лет назад
It is 2018, I don't understand why such topic exists!! Developer MUST know such thing almost from the very beginning of career. And no, you will not get duplicate symbol error. Linker will take symbol from the first object/library file it has in input. This way linkers work at least 20 years. I've gained huge benefit of this.
@noxabellus
@noxabellus 5 лет назад
@@higaski Yeah and them not knowing this type of stuff is why those fields host some of the least performant, poorly designed code in the world. Not saying they need to know the specific stuff covered in this video but using these fields as an example of something that works without low level knowledge is giving them way too much credit.
@ShakkIsLife
@ShakkIsLife 5 лет назад
I'm sure many developers don't know this topic well and comments like this are why the online tech community is terrible, especially for beginners.
@jakearkinstall5313
@jakearkinstall5313 5 лет назад
5000 views in one day on a specialised topic like this, as well as the overwhelmingly positive feedback, is evidence to how wrong you are.
@HalfdanIngvarsson
@HalfdanIngvarsson 5 лет назад
"And no, you will not get duplicate symbol error. Linker will take symbol from the first object/library file it has in input. This way linkers work at least 20 years. I've gained huge benefit of this." I don't know which linker you've been using, but all the linkers I've been working with for the last three decades, or so, soundly reject linking object files with duplicate, globally visible symbols into a single binary. Sure, if you mark them as local to the translation unit, via 'static', or as weak references via 'inline', then it'll happily link them, but otherwise, no. > echo "void foo() {}" > test1.c > echo "void foo() {}; int main() {}" > test2.c > cc -o t test1.c test2.c FAIL And, no. I would absolutely not expect anyone who works for me to understand this, in the same way I don't expect them to understand the implementation of tgamma(3) or how exceptions are implemented under the hood on any platform. There are bigger things to worry about. Also, knowing this stuff pays /my/ bills ;-)
@tarickw
@tarickw 5 лет назад
why are you watching a video from a C++ conference and are saying that everybody needs to know every little thing. The whole point of C++ is good abstractions, which in turn can be used to build better abstractions so that people DON'T need to know all the nitty gritty details. That of course doesn't mean that some developers need to know such details. The branching limitations of arm is such a detail that embedded developers should be aware off.
@SmugDarkLoser10
@SmugDarkLoser10 2 года назад
This is one of the few language talks at a conference that I find actually useful. Usually this stuff feels like language trivia, but this actually has a level of depth that really impressed me. Good job here.
@jaime7295
@jaime7295 4 месяца назад
this is by far my favoirite C++ talk!!
@ansakyt
@ansakyt 2 года назад
Oh wow... not just great technical content but reference to some really interesting music. It's a sign of how sheltered my life has been that I'd never heard of Ozric Tentacles before. Thanks Matt! For the tool (compiler explorer), the talk and the tunes...
Далее
CppCon 2018: John Woolverton “Interfaces Matter”
35:49
CppCon 2018: Jason Turner “Applied Best Practices”
1:03:19
🎙ПЕСНИ ВЖИВУЮ от КВАШЕНОЙ
3:05:21
Самая сложная маска…
00:32
Просмотров 747 тыс.
Being Competent With Coding Is More Fun
11:13
Просмотров 77 тыс.
CppCon 2017: Chandler Carruth “Going Nowhere Faster”
1:00:58
The Tragedy of systemd
47:18
Просмотров 1,1 млн
🎙ПЕСНИ ВЖИВУЮ от КВАШЕНОЙ
3:05:21