From b314d47f3cf77b97f16ebeb02271b9e05d74e978 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sat, 21 Dec 2024 09:37:59 -0700 Subject: [PATCH] ELF and threads. --- .../plugins/obsidian-to-anki-plugin/data.json | 11 +- notes/_journal/2024-12-21.md | 9 + notes/_journal/{ => 2024-12}/2024-12-19.md | 0 notes/_journal/2024-12/2024-12-20.md | 11 + notes/encoding/xml.md | 2 +- notes/linkers/elf.md | 196 +++++++++++++++++- notes/threads/index.md | 40 ++++ 7 files changed, 263 insertions(+), 6 deletions(-) create mode 100644 notes/_journal/2024-12-21.md rename notes/_journal/{ => 2024-12}/2024-12-19.md (100%) create mode 100644 notes/_journal/2024-12/2024-12-20.md create mode 100644 notes/threads/index.md diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index 9da414e..6337950 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -1016,7 +1016,7 @@ "_journal/2024-12/2024-12-10.md": "d4f43b32220dbe174be514397b1bb035", "_journal/2024-12/2024-12-11.md": "e7393c01b44c5b804f86f45b8b899b59", "encoding/uri.md": "394abe477b882e1414dd2fb151fea823", - "encoding/xml.md": "5b345c09ac60821f88ed5b592e411df6", + "encoding/xml.md": "01a66b1a102cccc682f8f1cab0f50bc6", "encoding/rdf.md": "f5c2c0156046a9474bae3577e739c5ce", "_journal/2024-12-15.md": "be66c8808d8bb66d4e7b91db7c93c94a", "_journal/2024-12/2024-12-14.md": "d2223f90fd1ce3d82a4fbb6828a1ec56", @@ -1025,7 +1025,7 @@ "linkers/object-files.md": "77767f310330b8650a5023dd0522226c", "_journal/2024-12-16.md": "d867a62a955f3d080ae25f31464d53c4", "_journal/2024-12/2024-12-15.md": "be66c8808d8bb66d4e7b91db7c93c94a", - "linkers/elf.md": "64262b8ec7d85bab4bd32a238beac638", + "linkers/elf.md": "cc24068cbf2599446b6bc0d1f612c7c5", "c17/strings/printf.md": "8b67cfbccaf35dd9488b73e7e5555405", "c17/strings/index.md": "3fa6f42967f3cc786740bb8537c62682", "_journal/2024-12-17.md": "ae55db66c9835876c4a0343ac0806951", @@ -1033,7 +1033,12 @@ "_journal/2024-12-18.md": "9cf32faceb4d52bf2303e8dcce7bda20", "_journal/2024-12/2024-12-17.md": "afea61b79ad8dcb02a99e385dce1bbc2", "_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": { "Basic": [ diff --git a/notes/_journal/2024-12-21.md b/notes/_journal/2024-12-21.md new file mode 100644 index 0000000..013dcdd --- /dev/null +++ b/notes/_journal/2024-12-21.md @@ -0,0 +1,9 @@ +--- +title: "2024-12-21" +--- + +- [x] Anki Flashcards +- [x] KoL +- [x] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) \ No newline at end of file diff --git a/notes/_journal/2024-12-19.md b/notes/_journal/2024-12/2024-12-19.md similarity index 100% rename from notes/_journal/2024-12-19.md rename to notes/_journal/2024-12/2024-12-19.md diff --git a/notes/_journal/2024-12/2024-12-20.md b/notes/_journal/2024-12/2024-12-20.md new file mode 100644 index 0000000..a24e354 --- /dev/null +++ b/notes/_journal/2024-12/2024-12-20.md @@ -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]]. \ No newline at end of file diff --git a/notes/encoding/xml.md b/notes/encoding/xml.md index dbebc14..4e878d1 100644 --- a/notes/encoding/xml.md +++ b/notes/encoding/xml.md @@ -249,7 +249,7 @@ Which namespace is attribute `b` a member of? ``` -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). END%% diff --git a/notes/linkers/elf.md b/notes/linkers/elf.md index acf2385..9ba3e21 100644 --- a/notes/linkers/elf.md +++ b/notes/linkers/elf.md @@ -156,6 +156,7 @@ Basic What kind of global/static C variables does the `.data` section of an ELF file contain? 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. +Tags: c17 END%% @@ -164,6 +165,7 @@ Basic Which ELF section contains global C variables initialized to a non-zero value? Back: `.data` Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 END%% @@ -172,6 +174,7 @@ Basic Which ELF section contains static C variables initialized to a non-zero value? Back: `.data` Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 END%% @@ -180,6 +183,7 @@ Basic Which ELF section contains local C variables initialized to a non-zero value? 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. +Tags: c17 END%% @@ -191,6 +195,7 @@ int foo = 1; ``` Back: `.data` Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 END%% @@ -204,6 +209,7 @@ int foo() { ``` 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. +Tags: c17 END%% @@ -217,9 +223,81 @@ int foo() { ``` Back: `.data`. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 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 + +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 + +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 + +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 + +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 + +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 + +END%% + ### `.bss` 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? 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. +Tags: c17 END%% @@ -237,6 +316,7 @@ Basic Which ELF section contains uninitialized global C variables? Back: `.bss` Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 END%% @@ -245,6 +325,7 @@ Basic Which ELF section contains global C variables initialized to a zero value? Back: `.bss` Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 END%% @@ -253,6 +334,7 @@ Basic Which two ELF sections contain global/static C variables? 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. +Tags: c17 END%% @@ -264,6 +346,7 @@ int foo = 0; ``` Back: `.bss` Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 END%% @@ -275,14 +358,16 @@ int foo; ``` Back: `.bss` Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 END%% %%ANKI Basic 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. +Tags: c17 END%% @@ -328,9 +413,115 @@ int foo() { ``` Back: `.bss`. Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: c17 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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +END%% + ### `.symtab` A symbol table with information about functions and global variables defined and referenced in the program. @@ -451,4 +642,5 @@ END%% ## Bibliography -* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. \ No newline at end of file +* 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. \ No newline at end of file diff --git a/notes/threads/index.md b/notes/threads/index.md new file mode 100644 index 0000000..347cd8d --- /dev/null +++ b/notes/threads/index.md @@ -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). + +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 + +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). + +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). \ No newline at end of file