Commit Graph

19 Commits

Author SHA1 Message Date
Mateusz Tabaka a7480ea656 Fix global symbols relocations
Instead of a single source of symbols, now linker keeps a list of DSO (former Library) objects
with their own symbols map. That helps to process R_X86_64_COPY relocations correctly.
For example, if 'a.out' executable with dependencies ['libstdc++.so', 'libc.so'] is being loaded
and 'a.out' uses 'stdout' symbol from 'libc.so', its relocation process goes as follows:
- linker processes relocation entry 'stdout' of type R_X86_64_GLOB_DAT from 'libc.so',
- it goes through object list ['a.out', 'libstdc++.so', 'libc.so'] to find first object
  that exports 'stdout' symbol. The symbol is in 'a.out' with the value e.g. '0x404070',
- linker sets 'stdout' symbol GOT entry in 'libc.so' to '0x404070',
....
- linker processes relocation entry 'stdout' of type R_X86_64_COPY from 'a.out',
- it goes through object list excluding 'a.out': ['libstdc++.so', 'libc.so']. The symbol is found in 'libc.so',
- linker copies the 'stdout' symbol content from 'libc.so' to memory at address '0x404070' (in 'a.out' object).

Objects are relocated in reverse order they were loaded. So in the example above, linker starts with relocating
'libc.so' and ends with 'a.out'. It is necessary e.g. when linking with 'libstdc++.so' - there are many
relocations which symbols are found in 'libstdc++.so', so they need to be resolved before their contents are
copied to 'a.out'. That also matches GNU ld.so behavior.
2021-01-03 16:04:40 +01:00
Jeremy Soller 05f71567ab Format 2019-07-06 19:37:13 -06:00
jD91mZM2 2f4e57f87a Fix data race inside puts(...) & add dbg!() macro 2019-06-26 21:21:32 +02:00
Jeremy Soller 5dca9843dc Fix use of trace macro when errno is imported 2019-03-27 20:57:12 -06:00
Jeremy Soller c71088e768 Cleanup and format 2019-01-14 21:07:24 -07:00
Jeremy Soller c57ac53d28 Reduce warnings 2019-01-14 19:26:18 -07:00
Jeremy Soller c41c20a943 Allow for static CStr 2019-01-06 14:40:01 -07:00
Jeremy Soller 0ac16556bc Format 2018-11-25 10:34:42 -07:00
Jeremy Soller a5279b648f Fix warnings 2018-11-25 10:34:02 -07:00
Jeremy Soller a29aa9f599 Add execvp 2018-11-16 21:07:24 -07:00
jD91mZM2 6dcc8ee8d9 Implement strtof 2018-10-02 18:47:42 +02:00
Jeremy Soller 9dbf49fdcd Format and add O_CLOEXEC where appropriate 2018-09-18 19:52:47 -06:00
Jeremy Soller 290ecb3e46 - fsync when tracing
- clean up trace macro some
2018-09-18 08:49:44 -06:00
Jeremy Soller 60f00508d3 Restore errno if trace_expr is successful 2018-09-18 08:34:06 -06:00
jD91mZM2 10a7944aef Avoid duplicate code 2018-09-18 08:08:55 +02:00
Jeremy Soller c2f4c1dbc9 Add trace macro and feature 2018-09-17 21:29:40 -06:00
Jeremy Soller 23098b694e Add print, eprint, eprintln, and fix println macros 2018-09-17 15:02:00 -06:00
jD91mZM2 49ccf364c2 Fix netdb getservbyname on names with spaces 2018-09-05 17:38:59 +02:00
Jeremy Soller 277b9abcd5 Fix build, mostly 2018-08-26 08:56:02 -06:00