ELF and threads.

main
Joshua Potter 2024-12-21 09:37:59 -07:00
parent 5bb40f0018
commit b314d47f3c
7 changed files with 263 additions and 6 deletions

View File

@ -1016,7 +1016,7 @@
"_journal/2024-12/2024-12-10.md": "d4f43b32220dbe174be514397b1bb035", "_journal/2024-12/2024-12-10.md": "d4f43b32220dbe174be514397b1bb035",
"_journal/2024-12/2024-12-11.md": "e7393c01b44c5b804f86f45b8b899b59", "_journal/2024-12/2024-12-11.md": "e7393c01b44c5b804f86f45b8b899b59",
"encoding/uri.md": "394abe477b882e1414dd2fb151fea823", "encoding/uri.md": "394abe477b882e1414dd2fb151fea823",
"encoding/xml.md": "5b345c09ac60821f88ed5b592e411df6", "encoding/xml.md": "01a66b1a102cccc682f8f1cab0f50bc6",
"encoding/rdf.md": "f5c2c0156046a9474bae3577e739c5ce", "encoding/rdf.md": "f5c2c0156046a9474bae3577e739c5ce",
"_journal/2024-12-15.md": "be66c8808d8bb66d4e7b91db7c93c94a", "_journal/2024-12-15.md": "be66c8808d8bb66d4e7b91db7c93c94a",
"_journal/2024-12/2024-12-14.md": "d2223f90fd1ce3d82a4fbb6828a1ec56", "_journal/2024-12/2024-12-14.md": "d2223f90fd1ce3d82a4fbb6828a1ec56",
@ -1025,7 +1025,7 @@
"linkers/object-files.md": "77767f310330b8650a5023dd0522226c", "linkers/object-files.md": "77767f310330b8650a5023dd0522226c",
"_journal/2024-12-16.md": "d867a62a955f3d080ae25f31464d53c4", "_journal/2024-12-16.md": "d867a62a955f3d080ae25f31464d53c4",
"_journal/2024-12/2024-12-15.md": "be66c8808d8bb66d4e7b91db7c93c94a", "_journal/2024-12/2024-12-15.md": "be66c8808d8bb66d4e7b91db7c93c94a",
"linkers/elf.md": "64262b8ec7d85bab4bd32a238beac638", "linkers/elf.md": "cc24068cbf2599446b6bc0d1f612c7c5",
"c17/strings/printf.md": "8b67cfbccaf35dd9488b73e7e5555405", "c17/strings/printf.md": "8b67cfbccaf35dd9488b73e7e5555405",
"c17/strings/index.md": "3fa6f42967f3cc786740bb8537c62682", "c17/strings/index.md": "3fa6f42967f3cc786740bb8537c62682",
"_journal/2024-12-17.md": "ae55db66c9835876c4a0343ac0806951", "_journal/2024-12-17.md": "ae55db66c9835876c4a0343ac0806951",
@ -1033,7 +1033,12 @@
"_journal/2024-12-18.md": "9cf32faceb4d52bf2303e8dcce7bda20", "_journal/2024-12-18.md": "9cf32faceb4d52bf2303e8dcce7bda20",
"_journal/2024-12/2024-12-17.md": "afea61b79ad8dcb02a99e385dce1bbc2", "_journal/2024-12/2024-12-17.md": "afea61b79ad8dcb02a99e385dce1bbc2",
"_journal/2024-12-19.md": "0064c8a827222092a55b3d896033b84b", "_journal/2024-12-19.md": "0064c8a827222092a55b3d896033b84b",
"_journal/2024-12/2024-12-18.md": "06f32ecf5bc088c6db98476fadfd0b5c" "_journal/2024-12/2024-12-18.md": "06f32ecf5bc088c6db98476fadfd0b5c",
"threads/index.md": "28783464146ed09603b477bad4b761bc",
"_journal/2024-12-20.md": "2e6b1826035eaa60aeb328f61d9bc976",
"_journal/2024-12/2024-12-19.md": "cd09c9e522a3b206b8a3524d615fadd5",
"_journal/2024-12-21.md": "51bc26a6ec147bd57e0efffd75c266c6",
"_journal/2024-12/2024-12-20.md": "3c896dac68ce1bfb1f28cb7da4325c6c"
}, },
"fields_dict": { "fields_dict": {
"Basic": [ "Basic": [

View File

@ -0,0 +1,9 @@
---
title: "2024-12-21"
---
- [x] Anki Flashcards
- [x] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)

View File

@ -0,0 +1,11 @@
---
title: "2024-12-20"
---
- [x] Anki Flashcards
- [x] KoL
- [x] OGS
- [ ] Sheet Music (10 min.)
- [ ] Korean (Read 1 Story)
* Initial notes on [[threads/index|thread-local storage]].

View File

@ -249,7 +249,7 @@ Which namespace is attribute `b` a member of?
<bar a="1" p:b="2" /> <bar a="1" p:b="2" />
</foo> </foo>
``` ```
Back: `p` Back: `ns1`
Reference: “XML Namespace,” in _Wikipedia_, April 11, 2024, [https://en.wikipedia.org/w/index.php?title=XML_namespace](https://en.wikipedia.org/w/index.php?title=XML_namespace&oldid=1218316095). Reference: “XML Namespace,” in _Wikipedia_, April 11, 2024, [https://en.wikipedia.org/w/index.php?title=XML_namespace](https://en.wikipedia.org/w/index.php?title=XML_namespace&oldid=1218316095).
<!--ID: 1733842094375--> <!--ID: 1733842094375-->
END%% END%%

View File

@ -156,6 +156,7 @@ Basic
What kind of global/static C variables does the `.data` section of an ELF file contain? What kind of global/static C variables does the `.data` section of an ELF file contain?
Back: Those initialized to a non-zero value. Back: Those initialized to a non-zero value.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734368832070--> <!--ID: 1734368832070-->
END%% END%%
@ -164,6 +165,7 @@ Basic
Which ELF section contains global C variables initialized to a non-zero value? Which ELF section contains global C variables initialized to a non-zero value?
Back: `.data` Back: `.data`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734368832073--> <!--ID: 1734368832073-->
END%% END%%
@ -172,6 +174,7 @@ Basic
Which ELF section contains static C variables initialized to a non-zero value? Which ELF section contains static C variables initialized to a non-zero value?
Back: `.data` Back: `.data`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734368832075--> <!--ID: 1734368832075-->
END%% END%%
@ -180,6 +183,7 @@ Basic
Which ELF section contains local C variables initialized to a non-zero value? Which ELF section contains local C variables initialized to a non-zero value?
Back: N/A. Back: N/A.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734368832076--> <!--ID: 1734368832076-->
END%% END%%
@ -191,6 +195,7 @@ int foo = 1;
``` ```
Back: `.data` Back: `.data`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734369188095--> <!--ID: 1734369188095-->
END%% END%%
@ -204,6 +209,7 @@ int foo() {
``` ```
Back: N/A. Back: N/A.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734369188101--> <!--ID: 1734369188101-->
END%% END%%
@ -217,9 +223,81 @@ int foo() {
``` ```
Back: `.data`. Back: `.data`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734369188110--> <!--ID: 1734369188110-->
END%% END%%
### `.tdata`
Thread-local global and static C variables initialized to a non-zero value.
%%ANKI
Basic
What kind of global/static C variables does the `.tdata` section of an ELF file contain?
Back: Thread-local variables initialized to a non-zero value.
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402941-->
END%%
%%ANKI
Basic
Which ELF section contains global thread-local C variables initialized to a non-zero value?
Back: `.tdata`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402945-->
END%%
%%ANKI
Basic
Which ELF section contains static thread-local C variables initialized to a non-zero value?
Back: `.tdata`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402949-->
END%%
%%ANKI
Basic
Consider the following translation unit. Which ELF section will `foo` end up in?
```c
_Thread_local int foo = 1;
```
Back: `.tdata`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402952-->
END%%
%%ANKI
Basic
Consider the following translation unit. Which ELF section will `bar` end up in?
```c
int foo() {
static _Thread_local int bar = 1;
}
```
Back: `.tdata`.
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402957-->
END%%
%%ANKI
Basic
Consider the following translation unit. Which ELF section will `bar` end up in?
```c
int foo() {
_Thread_local int bar = 1;
}
```
Back: N/A. Compilation error - `bar` must have global storage.
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402961-->
END%%
### `.bss` ### `.bss`
Uninitialized global and static C variables, along with any global or static variables initialized to zero. Uninitialized global and static C variables, along with any global or static variables initialized to zero.
@ -229,6 +307,7 @@ Basic
What kind of global/static C variables does the `.bss` section of an ELF file contain? What kind of global/static C variables does the `.bss` section of an ELF file contain?
Back: Unitialized variables or those initialized to zero. Back: Unitialized variables or those initialized to zero.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734368832077--> <!--ID: 1734368832077-->
END%% END%%
@ -237,6 +316,7 @@ Basic
Which ELF section contains uninitialized global C variables? Which ELF section contains uninitialized global C variables?
Back: `.bss` Back: `.bss`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734368832078--> <!--ID: 1734368832078-->
END%% END%%
@ -245,6 +325,7 @@ Basic
Which ELF section contains global C variables initialized to a zero value? Which ELF section contains global C variables initialized to a zero value?
Back: `.bss` Back: `.bss`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734368832079--> <!--ID: 1734368832079-->
END%% END%%
@ -253,6 +334,7 @@ Basic
Which two ELF sections contain global/static C variables? Which two ELF sections contain global/static C variables?
Back: `.data` and `.bss` Back: `.data` and `.bss`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734368832080--> <!--ID: 1734368832080-->
END%% END%%
@ -264,6 +346,7 @@ int foo = 0;
``` ```
Back: `.bss` Back: `.bss`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734369188113--> <!--ID: 1734369188113-->
END%% END%%
@ -275,14 +358,16 @@ int foo;
``` ```
Back: `.bss` Back: `.bss`
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734369188117--> <!--ID: 1734369188117-->
END%% END%%
%%ANKI %%ANKI
Basic Basic
Both `.bss` and `.data` hold what kind of C variables? Both `.bss` and `.data` hold what kind of C variables?
Back: Global or static C variables. Back: Global or static variables.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734369188121--> <!--ID: 1734369188121-->
END%% END%%
@ -328,9 +413,115 @@ int foo() {
``` ```
Back: `.bss`. Back: `.bss`.
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
Tags: c17
<!--ID: 1734369188106--> <!--ID: 1734369188106-->
END%% END%%
### `.tbss`
Uninitialized global and static thread-local C variables, along with any global or static thread-local variables initialized to zero.
%%ANKI
Basic
What kind of global/static C variables does the `.tbss` section of an ELF file contain?
Back: Unitialized thread-local variables or those initialized to zero.
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402964-->
END%%
%%ANKI
Basic
Which ELF section contains uninitialized thread-local global C variables?
Back: `.tbss`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402968-->
END%%
%%ANKI
Basic
Which ELF section contains global thread-local C variables initialized to a zero value?
Back: `.tbss`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402971-->
END%%
%%ANKI
Basic
Which two ELF sections contain global/static thread-local C variables?
Back: `.tdata` and `.bss`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402975-->
END%%
%%ANKI
Basic
Consider the following translation unit. Which ELF section will `foo` end up in?
```c
_Thread_local int foo = 0;
```
Back: `.tbss`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402980-->
END%%
%%ANKI
Basic
Consider the following translation unit. Which ELF section will `foo` end up in?
```c
_Thread_local int foo;
```
Back: `.tbss`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402984-->
END%%
%%ANKI
Basic
Both `.tbss` and `.tdata` hold what kind of C variables?
Back: Global or static thread-local variables.
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402989-->
END%%
%%ANKI
Basic
Which of `.tdata` and/or `.tbss` is considered a "placeholder"?
Back: `.tbss`
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402993-->
END%%
%%ANKI
Basic
How does the size of the `.tbss` section compare to that of the `.tdata` section?
Back: Less than or equal since the `.tbss` section is always empty.
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745402997-->
END%%
%%ANKI
Basic
Consider the following translation unit. Which ELF section will `bar` end up in?
```c
int foo() {
static _Thread_local int bar = 0;
}
```
Back: `.tbss`.
Reference: Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.
Tags: c17
<!--ID: 1734745403003-->
END%%
### `.symtab` ### `.symtab`
A symbol table with information about functions and global variables defined and referenced in the program. A symbol table with information about functions and global variables defined and referenced in the program.
@ -452,3 +643,4 @@ END%%
## Bibliography ## Bibliography
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. * Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
* Ulrich Drepper, “ELF Handling For Thread-Local Storage,” n.d.

40
notes/threads/index.md Normal file
View File

@ -0,0 +1,40 @@
---
title: Threads
TARGET DECK: Obsidian::STEM
FILE TAGS: threads
tags:
- threads
---
## Overview
**Thread-Local Storage** (TLS) is a memory management method that uses static or global memory local to a thread. In C17, the keyword `_Thread_local` is used for defining thread-local variables.
%%ANKI
Basic
In the context of memory management, what is TLS an acronym for?
Back: **T**hread-**L**ocal **S**torage.
Reference: “Thread-Local Storage,” in _Wikipedia_, October 21, 2024, [https://en.wikipedia.org/w/index.php?title=Thread-local_storage](https://en.wikipedia.org/w/index.php?title=Thread-local_storage&oldid=1252543227).
<!--ID: 1734745402895-->
END%%
%%ANKI
Basic
What storage class specifier is used to modify TLS?
Back: `_Thread_local`
Reference: “Thread-Local Storage,” in _Wikipedia_, October 21, 2024, [https://en.wikipedia.org/w/index.php?title=Thread-local_storage](https://en.wikipedia.org/w/index.php?title=Thread-local_storage&oldid=1252543227).
Tags: c17
<!--ID: 1734745402931-->
END%%
%%ANKI
Basic
What is thread-local storage?
Back: A memory management method that uses static or global memory local to a thread.
Reference: “Thread-Local Storage,” in _Wikipedia_, October 21, 2024, [https://en.wikipedia.org/w/index.php?title=Thread-local_storage](https://en.wikipedia.org/w/index.php?title=Thread-local_storage&oldid=1252543227).
<!--ID: 1734745402937-->
END%%
## Bibliography
* “Thread-Local Storage,” in _Wikipedia_, October 21, 2024, [https://en.wikipedia.org/w/index.php?title=Thread-local_storage](https://en.wikipedia.org/w/index.php?title=Thread-local_storage&oldid=1252543227).