Browse Source

Add scouts honor escape hatch for source embedding

main
Justine Tunney 1 year ago
parent
commit
b4269930f7
  1. 9
      Makefile
  2. 197
      README.md
  3. 10
      ape/ape.S
  4. 130
      ape/ape.lds
  5. 43
      ape/ape.mk
  6. 2
      ape/lib/apelib.mk
  7. 2
      ape/lib/bootdr.S
  8. 2
      ape/lib/e820map.S
  9. 2
      ape/lib/g_pml4t.S
  10. 2
      ape/lib/g_ptsp.S
  11. 2
      ape/lib/kbiosdataarea.S
  12. 4
      build/definitions.mk
  13. 21
      build/objdump
  14. 2
      dsp/core/mulaw.S
  15. 2
      dsp/core/sad16x8n.S
  16. 2
      dsp/mpeg/clamp4int256-core.S
  17. 2
      dsp/tty/windex-avx2.S
  18. 2
      dsp/tty/windex-sse4.S
  19. 2
      dsp/tty/windex.S
  20. 0
      examples/package/README.md
  21. 63
      examples/package/lib/lib.mk
  22. 6
      examples/package/lib/myasm.S
  23. 10
      examples/package/lib/myprint.c
  24. 11
      examples/package/lib/myprint.h
  25. 33
      examples/package/new.sh
  26. 74
      examples/package/package.mk
  27. 6
      examples/package/program.c
  28. 35
      examples/tiny-raw-linux-tutorial.S
  29. 2
      libc/alg/djbsort-avx2.S
  30. 2
      libc/calls/g_ntstartupinfo_init.S
  31. 2
      libc/calls/g_ntsysteminfo_init.S
  32. 2
      libc/calls/getntsyspath.S
  33. 1
      libc/calls/hefty/mkntcmdline.c
  34. 1
      libc/calls/hefty/mkntenvblock.c
  35. 2
      libc/calls/ktmppath.S
  36. 1
      libc/calls/mkntpath.ncabi.c
  37. 2
      libc/calls/onntconsoleevent_init.S
  38. 2
      libc/calls/onwincrash_init.S
  39. 2
      libc/calls/pipe-sysv.S
  40. 2
      libc/calls/setegid.S
  41. 2
      libc/calls/seteuid.S
  42. 2
      libc/calls/sigenter.S
  43. 2
      libc/calls/thunks/ftruncate-sysv.S
  44. 2
      libc/calls/thunks/gettemppatha-flunk.S
  45. 2
      libc/calls/thunks/lseek-sysv.S
  46. 2
      libc/calls/thunks/mmap-sysv.S
  47. 2
      libc/calls/thunks/onntconsoleevent.S
  48. 2
      libc/calls/thunks/onwincrash.S
  49. 2
      libc/calls/thunks/pread-sysv.S
  50. 2
      libc/calls/thunks/preadv-sysv.S
  51. 2
      libc/calls/thunks/pwrite-sysv.S
  52. 2
      libc/calls/thunks/pwritev-sysv.S
  53. 2
      libc/calls/thunks/truncate-sysv.S
  54. 2
      libc/crt/crt.S
  55. 2
      libc/fmt/kerrnonames.S
  56. 2
      libc/fmt/stoa.c
  57. 23
      libc/integral/c.inc
  58. 2
      libc/log/loglevel.S
  59. 2
      libc/log/oncrashthunks.S
  60. 2
      libc/log/thunks/__check_fail_eq.S
  61. 2
      libc/log/thunks/__check_fail_ge.S
  62. 2
      libc/log/thunks/__check_fail_gt.S
  63. 2
      libc/log/thunks/__check_fail_le.S
  64. 2
      libc/log/thunks/__check_fail_lt.S
  65. 2
      libc/log/thunks/__check_fail_ndebug.S
  66. 2
      libc/log/thunks/__check_fail_ne.S
  67. 2
      libc/log/ubsanjmp.S
  68. 11
      libc/macros-cpp.inc
  69. 2
      libc/math/__fesetround.S
  70. 4
      libc/math/feraiseexcept.S
  71. 2
      libc/math/fesetenv.S
  72. 2
      libc/math/fetestexcept.S
  73. 2
      libc/mem/calloc-hook.S
  74. 2
      libc/mem/calloc.S
  75. 2
      libc/mem/free-cxx.S
  76. 2
      libc/mem/free-hook.S
  77. 2
      libc/mem/free.S
  78. 2
      libc/mem/malloc-cxx.S
  79. 2
      libc/mem/malloc-hook.S
  80. 2
      libc/mem/malloc.S
  81. 2
      libc/mem/malloc_usable_size.S
  82. 2
      libc/mem/memalign-cxx.S
  83. 2
      libc/mem/memalign-hook.S
  84. 2
      libc/mem/memalign.S
  85. 2
      libc/mem/posix_memalign.S
  86. 2
      libc/mem/pvalloc.S
  87. 2
      libc/mem/realloc-hook.S
  88. 2
      libc/mem/realloc.S
  89. 2
      libc/mem/realloc_in_place.S
  90. 2
      libc/mem/valloc.S
  91. 2
      libc/nexgen32e/atomicislockfree.S
  92. 2
      libc/nexgen32e/bcmp.S
  93. 4
      libc/nexgen32e/bcopy.S
  94. 2
      libc/nexgen32e/bsf.S
  95. 2
      libc/nexgen32e/bsfl.S
  96. 2
      libc/nexgen32e/bsr.S
  97. 2
      libc/nexgen32e/bsrl.S
  98. 2
      libc/nexgen32e/bsrmax.S
  99. 2
      libc/nexgen32e/bzero.S
  100. 2
      libc/nexgen32e/cescapec.S

9
Makefile

@ -40,10 +40,12 @@
# o/dbg/examples/crashreport.com
# less examples/crashreport.c
#
# # extremely tiny binaries
# # extremely tiny binaries (scout's honor escape hatch)
# # please pay the $1k for commercial license if you can
# make -j8 -O MODE=tiny \
# LDFLAGS=-s \
# CPPFLAGS=-DSUPPORT_VECTOR=0b00000001 \
# LDFLAGS+=-s \
# CPPFLAGS+=-DIM_FEELING_NAUGHTY \
# CPPFLAGS+=-DSUPPORT_VECTOR=0b00000001 \
# o/tiny/examples/hello4.elf
# ls -hal o/tiny/examples/hello4.elf
# o/tiny/examples/hello4.elf
@ -192,6 +194,7 @@ include test/dsp/core/test.mk
include test/dsp/scale/test.mk
include test/dsp/tty/test.mk
include test/dsp/test.mk
#-φ-examples/package/new.sh
OBJS = $(foreach x,$(PKGS),$($(x)_OBJS))
SRCS = $(foreach x,$(PKGS),$($(x)_SRCS))

197
README.md

@ -24,6 +24,26 @@ without the costs and restrictions cross-platform distribution entails.
That makes Cosmopolitan an excellent fit for writing small CLI programs
that do things like heavyweight numerical computations as a subprocess.
## Getting Started
Just clone the repository and put your own folder in it. Please choose a
name that's based on a .com or .org domain name registration you control
which is scout's honor but might change to require TXT records in future
We provide a script that makes it easy to start a new package:
examples/package/new.sh com/github/user/project
emacs com/github/user/project/program.c
make o//com/github/user/project/program.c
o//com/github/user/project/program.c
Please note GNU make is awesome. Little known fact: make is a functional
programming language. We've improve upon it too see tool/build/package.c
which performs strict dependency checking, to correct Google's published
mistakes c. 2006 which was when they switched from using a GNU Make repo
in favor of an inhouse derivative called Blaze which does strictness too
thereby allowing the repository to grow gracefully with any requirements
## Licensing
Cosmopolitan is Free Software licensed under the GPLv2. The build config
@ -41,6 +61,24 @@ you want your license to last 5 years, send $10,000 to the author above
who is Justine Tunney <jtunney@gmail.com>. This README will be updated,
if pricing and other details should change. Reach out for more details.
## Integrated Development Environment
Your Cosmopolitan IDE is based on Emacs. When used alongside `make tags`
it can automate certain toilsome problems such as adding an include line
by typing `C-c C-h` with the cursor over a symbol. Please install these:
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
sudo apt install gdb ragel ctags clang-format-10 # <-recommended
git clone git@github.com:jart/cosmopolitan.git && cd cosmopolitan
tool/scripts/install-emacs.sh # recommended over apt
tool/scripts/configure-emacs.sh # adds load statements
make tags # index all the symbol
emacs # for power and glory!
See [tool/emacs/cosmo-stuff.el] for further details. Noting what enables
the to work so well and fast is our break with tradition by using rooted
quoted include statements while vendoring the transitive closure of deps
## Contributing
We'd love to accept your patches! Before we can take them, we have to
@ -49,3 +87,162 @@ jump through one legal hurdle. Please write an email to Justine Tunney
any changes you contribute to Cosmopolitan. We need to do that in order
to dual license Cosmopolitan. Otherwise we can't tax corporations that
don't want to share their code with the community.
## Volunteering
We also need volunteers who can help us further stabilize System Five's
application binary interface. See our ABI scripts [libc/sysv/consts.sh]
and [libc/sysv/syscalls.sh]. Magic numbers are usually stabler than API
interfaces cf. NPM but we should ideally have fewer of them, similar to
how SI has sought to have fewer defining physics constants.
## Specimen
Cosmopolitan encodes binaries respecting the intersection of reasonable
platform requirements. That's easy to accomplish w/ binary isomorphisms
evidenced below by the RADIX256 disassembly below for [examples/life.c]
which ld is configured to overlay pe/elf/macho/bourne/bootloader in 12k
Please send feedback and concerns to <jtunney@gmail.com> since we would
love to do an even better job. Please also report GPL abuse the address
above as well. We believe this binary structure is novel, and therefore
easily recognizable. So if some goofball isn't bundling the source code
please let us know so we can reach out and ask they consider a license.
make -j10 -O MODE=tiny CPPFLAGS=-DIM_FEELING_NAUGHTY
o/tiny/tool/viz/bing.com <o/tiny/examples/life.com |
o/tiny/tool/viz/fold.com
MZqFpD=‘◙  ► °       ☺ ◘@           JT                      p♂  
▓@δ δ◄ÉÉδ♥R1╥╜  δ♣Θ⌐☼  ⁿ┐ p1╔·Ä╫ë╠√♫XΦ  ^üεh ▒♦╤εâΘ☺u∙╣ ☻┐ ♦Ä▐Ä╟
1÷1λ≤ñΩï@  ╣ ■≤ñ1φÄ▌Φ  Uëσ╣ 0╕ ☺Ä└1└1λ≤¬Ç·@t#Φ. ╕ ♦Ä└┐↑ 0÷1╔ë°Φ]
 î╞â╞ Ot•Hu≈Ä╞δ∞ë♫@2ë▬B2Ω3E  ◙SR┤◘═‼r,ê╧Çτ⁇Çß└╨┴╨┴å═▲♠▼1÷Ä╞╛ 2ç≈
ÑÑÑÑÑñ▼ô½æ½Æ½X¬Æ[├ZÇ≥Ç1└═‼r≈δ┴S1█è▲♀29├w☻ë╪QP╗ ►î└)├üπλ☼╣♣ ╤δâΘ☺
u∙XYà█t♠9├w☻ë╪PQå═╨╔╨╔Ç╔☺1█┤☻═‼Y[r‼┤ 9├|♪A;♫♪2~♦1╔■╞[├P1└═‼Xδ╨  
                                                                
                                                              U¬
‘◙#‘“◙o=“$(command -v “$0“)“◙set -- “$o“ “$@“◙if [ -d /Applicati
ons ]; then◙dd if=“$o“ of=“$o“ bs=8 skip=“ 410“ count=“
87“ conv=notrunc 2>/dev/null◙elif exec 7<> “$o“; then◙printf ‘╲
177ELF╲2╲1╲1╲011╲0╲0╲0╲0╲0╲0╲0╲0╲2╲0╲076╲0╲1╲0╲0╲0╲134╲022╲100╲0
00╲000╲000╲000╲000╲150╲012╲000╲000╲000╲000╲000╲000╲000╲000╲000╲0
00╲000╲000╲000╲000╲0╲0╲0╲0╲100╲0╲070╲0╲004╲000╲0╲0╲000╲000╲000╲0
00‘ >&7◙exec 7<&-◙fi◙exec “$@“◙R=$⁇◙if [ $R -eq 126 ] && [ “$(un
ame -m)“ != x86_64 ]; then◙if Q=“$(command -v qemu-x86_64)“; the
n◙exec “$Q“ “$@“◙else◙echo error: need qemu-x86_64 >&2◙fi◙fi◙exi
t $R◙αcτμαlly pδrταblε εxεcμταblε♪◙ error:  ♪◙ cpuid oldskool ds
knfo e820 nomem nolong hello◙ ♀  Cf☼▼D  8 ╕D      f☼▼D          
λλ   Ü☼ λλ   Æ☼ λλ   Ü╧ λλ   Æ╧ λλ   ¢» λλ   ô» ☻░¡←  ☺ ■OQΣ≡♦  
  ►  0►  @► ►♣  =☻░¡+☼à↑♪  j ¥▓@☼ └âα■☼“└fΩW@  ÉÉÉÉUëσΦ§♪Φ↓ ┐• î
♠▬2ú↑2Φ(☺┐EDΦÑ Φ╨♀Φ→☻Uëσ╣♦ ╛ 0¼ê┬¼ê╞à╥t♀QVë╫╛€DΦ○ ^YâΘ☺uσ]├Uëσë·
à╥t↑RV1╔▒♥☺╩¼^♀ÇεZ¼εâ┬☺âΘ☺y÷]├UëσΦ↕ Φ  Uëσ┐ 0╛♦ ΦÇ ΦÉ☺Uëσï╖☻0à÷u
♦ï6 01└PV╕lDPVWV╕dDP_àλt♠^Φ♦ δ⌡]├UëσWVΦ♂ ^_à÷t♥Φ↨ ]├Uëσë■─>▬2Φ╕ 
î♠▬2ú↑2]├UëσSë√ç▐¼ç▐ä└t↑ë╟VP╕  δ◘XΦ.   δ♦XΦ( ^δ▀[]├ë±ë■1╥¼ê┬¼ê╞à
└t◄â┬♣┤@∞ α≤Ét∙âΘ☺uσ├PQRë≥â┬♣┤ ∞ αu♦≤Éδ≈ë°ë≥εZYX├UëσS┤╕░ Ä└ë°<♥t
☻0φ1λj X═►┤☺░ ╡ ▒ ═►┤►░♥╖ │ ═►1└[]├Uëσâ∞►ûë∙ëμëτ¬ë╧j☺Zδ♫V¼ä└u√ë≥
^)≥UëσSë╤ë·ÇΓ ÇμÇÇ┬áÇ╓☼╖ │á9·t)w↕¼<◙t↕<♪t↕¬░•¬âΘ☺uΦë°[]├☺▀δ≥ë°R1
╥≈√)╫ZδμPQRVë▐P╕  δ◘XΦ♫   δ♦XΦ◘ ë╟^ZYXδ╞≈╥ë∙Çß ÇσÇç╧)±Q)∙ë■☺╬╕  
▲•≤ñX├Uëσ╕ S1█═§r→ü√MPu¶╕☺S1█═§1█1╔╕•S│☺▒♥═§Φ╢◙UëσΦ↔ Φy☺┐ ►╛  Φz
 r○Φ╟ Φ∞ Φ‘☻╕àDΦ♀■Uëσ£X% puMf£fXfë┴f╗    f1╪fPf¥f£fXf9┴t:f!╪fPf¥
f┐   Çfë°fG☼óf9°|∟fë°☼óf┐    f!·f9·u○1└]├╕uDδ◙╕ÉDδ♣╕oDδ Φú²Uëσfh
PAMSS┴∩♦Ä╟f1λf1█f╕ Φ  f╣↑   fïVⁿ═§r&f;Fⁿu à╔t♫â∙§r♠÷E¶☺u♥â╟↑fà█t
♦9≈r╦ë°[╔├∙δ·Uëσ·☼☺▬¿D☼ └♀☺☼“└δ ╣  Äß$■☼“└fΩrH    √]├UëσSf╛ @  f
╗  ► f╣↑   f┴ß○fâ╩ⁿfâ┬♦f9╤t♫dgfï♦▬dgfë♦‼δΘgfì∟‼┐  ╕ └ï♫@2ï▬B2à
λt+ë°S1█ΦS°[)╟Që┴┴ß○1÷&fï♦dgfë♥fâ├♦â╞♦âΘ♦uδYδ╤[]├·▲1└Ä└HÄ╪┐ ♣╛►♣
&è♣Pè♦P&╞♣ ╞♦λ&Ç=λXê♦X&ê♣▼u@╕☺ Φ, ░¡μdΦ% ░╨μdΦ% Σ`PΦ↑ ░╤μdΦ◄ X♀☻
μ`Φ○ ░«μdΦ☻ δúΣd¿☻u·├Σd¿☺t·├√├Uëσ▲╕ lÄ╪f╟♠ 0♥α♠ f╟♠  ♥╨♠ f╟♠ ►♥└
♠ ╣ ☺f╕♥   1÷fë♦f♣ ►  â╞◘âΘ☺u∩▼f╟♠ 2 └♠ f╕ ≡♠ ☼“╪]├·☼☺▲02Φóλ☼ αf
♪á☻  ☼“αf╣Ç  └☼2f♪☺☺  ☼0☼☺▬¿D☼ └f♪♥  Çfâα√☼“└Ω≥I( ╕0   Ä╪ÄαÄΦ1╥δ
 HâΣ≡1φ1λΦ]•  ┐ ►  Φ{•  ┐ ►  ╛ ≡♠ ║ 2  Φ≡♣  ┐ùD  ï4% 0  Φ╠√λλ┐ 0
  ╛♦   Φτ√λλΘΓ•  Hì§█•  Φλ•  Θ╤•  É☼▼D  ☺   ♣             @     
  ►                      ►      ☺   ♠             @       ►     
 ►               ►      Qσtd♠                                   
        ►       ♦   ♦   P♂      P♂@     P♂►     ↑       ↑       
◘       É☼▼Ç    ◘   ♦   ☺   OpenBSD     É☼▼Ç    PE  då☻ k↕d╲    
    ≡ #☻♂☻♫☼            ╞¶        @      ►   ►  ♠       ♠       
 @   ►      ♥  ☺  ►       ♥       ◘      ►          ►           
ä←  (                                                           
                        ►   @                           .text   
 ►   ►   ►   ►              `  p.data            ►              
    └  └É☼▼Ç    ╧·φ■•  ☺♥   ☻   ♣   ÿ☻  ☺       ↓   H   __PAGEZE
RO                                                      ↓   ÿ   
__TEXT            @                             •   ♣   ☺       
__text          __TEXT           ►@      ►       ►  ♀           
 ♦              ↓   Φ   __DATA            @                     
 ►      •   ♥   ☻       __data          __DATA            @     
 ►          ♀                           __bss           __DATA  
         0@      ►          ♀           ☺               ←   ↑   
B)→☺&¿◘ºB)→☺&¿◘º♣   ╕   ♦   *             @                     
                                                                
                                S↕@                             
        Éf.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä
     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f☼▼ä     
ZAR╕    Hà└t◙Hà└t♣Θ»♦  Θ@☻  UHë╤HëσAWIë≈AVA╛  @ AUIë²ATA╝  ► SHë
√Hâ∞↑Hâ{◘ ☼ä╕   ïS►Hë╪Hâ├↑λ╩t○Hâ{◘ uδδ♥Hë├L9#L☼C#Iü─λ☼  IüΣ ≡λλH
ïC◘H♥♥H% ≡λλI9─snIïU◘Hà╥t↓Aâ}►☺u♠Iâ┼↑δΩIïE H☺╨L9αrεIïE L9αw◄H☺╨L
9αv○Lìáλ☼  δ½Lë·Lë≈╛♥   HëM╚Φ6   LëΓHïM╚Iü╞ ►  Hâ╩♥Iü─ ►  Hë►δÇH
â├↑Θ=λλλHâ─↑[A╲A]A^A_]├I╣ ≡λλλλ♥ Ië╚╣‘   Hë°λ╬H╙Φ%λ☺  â■λu♣Hì♦┬├
Hì¶┬Hâ: u‼Iï H- ►  Ië Hâ╚♥Hë☻Hï☻âΘ○L!╚Hë┬δ╛U╣ 2  ║ ≡♠ ╛♥   HëσSH
ë√PΦÅλλλHâ ■☼☺;Z[]├1÷ë≡Hk└↑Hâ|•◘ t♦λ╞δεA╕☺   HìW↑A9≡r☺├UHëσATSLï
◙HïZ◘Hë╤Dë└DïZ►DïR¶Aë─λ╚L;IΦt→☼►AΦLïa°HâΘ↑☼◄A↑Lëa(à└u▌δ♥DëαHk└↑A
λ└Hâ┬↑H☺°Lë◘HëX◘DëX►DëP¶A9≡rí[A╲]├1└├UëσSç█[fÉ╠·⌠δ²Uëσâ∞◘U^ì~°j◘
Y1└≤¬·☼☺^°☼♂δ≈Uëσ]├╞♣ª↔  ◘δ►HàλH☼Eτt•╞♣ö↔   Lc$$Lìl$◘NìtΣ↑╕“↕@ ┐
► @ ╣P @ H)∙┴Θ♥≤H½1└â╔λLë≈≥H»IëλΘ╧   UHëσ┐ 0@ ╛°←@ ╣00@ HìA►Hë☺╟
A◘ ♥  SV÷•◘u<÷• u!÷•♦u◄Iâ⁇ t!j j☺╛ⁿ←@ δ*j“j♦╛☻∟@ δ▼j0j ╛∙←@ δ¶j*
j►╛λ←@ δ○jEj◘╛♦∟@ ╣q↓@ XH½XH☺╚H½W┐↑0@ Iâ╔λ╗(0@ H9▀s51╔1╥¼Ië└Aâα⌂
I╙αâ┴•L○┬ä└xδ¿@t○Lë╚H╙αH○┬Hë╨Hâ⁇ H☼E•H½δ╞_^[╔├╕*   ├HâΣ≡1φ╗  @ Φ
!λλλâ♪┴▼  ☺╕◘ @ ╣◘ @ H9┴t♀PQλ►YXHâ└◘δ∩ÉLëτLëεLë≥Φ╣λλλë╟Φ    UHëσ
ATAëⁿ1λPΦr   DëτΦö♠  1÷1╥UHëσAW╣00@ Ië╧Iï•IïO◘Hà╔t∟HâΘ↑Hë¶◘Hët◘◘
Hë|◘►IëO◘1└A_]├╣    Hà╔t≥PWVj!_j►^λ╤^_YHà└t▀I╟└ ♥  Ië•Jë♀ Lë┴δ┤U
HëσAVAUATHï5α←  Ië■Ië⌠j YH¡HÆH¡HùH¡Hà└t↑Mà÷δ♣L9≥u♫VQQλ╨YY^1└HëF°
âΘ☺u╘H¡Hà└t◄Mà÷t○PLëτΦfδ┐λ^δ╢A╲Mà÷u←╕► @ ╣► @ HâΦ◘H9╚|◘PQλ►YXδ∩A
]A^]├╠U╣ ◘  1└HëσAWAVAUATSHü∞Hα  Hëà└▼λλHëà╚▼λλλ§C♂  Hâ─ à└uGHâ∞
H╟┴⌠λλλ맓♂  Hâ─↑A╕♠   Lìì╨⌂λλj Hë┴║⌐→@ Hâ∞ λ§♪♂  XZ╣☺   λ§╨◙  
Hâ─ Hâ∞ j♦Xë♣»→  λ§╔◙  Ië─λ§╚◙  LëτHâ─ A╕ ☻  Hìì╨/λλ║λ⁇  Hì╡╤⁇λλ
Ië┼Φ╙☺  Aë─1└Hïì╨/λλH☺┴è◄ä╥t♪Ç·╲u♥╞☺/Hλ└δπA☼╖E f=λ╫w♪ëà╝▼λλ╕☺   
δ☼Hì╡╝▼λλLë∩Φ0♦  ë└Hìì╨⌂λλE1└1█H☺└Ië╦LìU╬A╛²⌂  IìT♣ Hì╡╝▼λλâ╜╝▼λ
λ ☼äÅ   Iλ└Iü°λ☺  w↕L9╤Hë╪H☼B┴Jëä┼╚▼λλDïì╝▼λλIc┴Aâ∙⌂v◘Dë╧ΦÉ♥  L9
╤s♀Hλ┴êAλH┴Φ◘u∩☼╖☻f=λ╫w♪ëà╝▼λλ╕☺   δ◘Hë╫Φö♥  ë└H☺└H☺┬Eà╔u¼Hë╚L)╪
H=²⌂  I☼G╞╞ä♣╨⌂λλ ΘdλλλL9╤s♠╞☺ Hλ┴L)┘╕■⌂  Lì╡╨▼λλHü∙■⌂  Lì╜└▼λλH
☼G╚Iü°λ☺  ╕λ☺  L☼G└Hâ∞ ╞ä♪╨⌂λλ LëΘLì¡╨/λλJ╟ä┼╨▼λλ    λ§↔○  Θtⁿλλ
Hë·Hï⁇☼╖•f=λ╫w◙ëB↑╕☺   δ○Hìr↑Φ▀☻  ë└H☺└H☺☻├Hë·Hc╞ë≈LïB►â■⌂v♣Φì☻ 
 HïJ◘I9╚v►Hìq☺Hër◘ê☺H┴Φ◘uτ├UHì♦▬Ië╙Më┬HëσAWI┐ &  ☺   AVAUIë⌡ATS1
█Hâ∞8Hë}░Hì}░HëM¿Hëu╕HëE└Φbλλλâ}╚ t↔ïE╚à└t▬â° w╲I☼ú╟sVHì}░ΦAλλλδ
π1÷Hì}░Φ_λλλMà█t↨HïE╕Iλ╦L)ΦL9╪I☼G├A╞D♣  Mà╥☼äf☺  Iλ╩HïE¿I9┌L☼G╙J
╟♦╨    ΘK☺  Hλ├L9╙s§HïE╕H;E└r☻1└HïU¿HëD┌°E1÷ïu╚à÷☼ä►☺  Eä÷u¶â■ w
☼I☼ú≈☼âσ   Θ≈   â■“t○â■╲☼à╥   E1Σâ}╚╲u♫Hì}░Iλ─Φì■λλδ∞E1╔â}╚“u♫Hì
}░Φy■λλIλ┴δ∞LëαMà╔u↓Iλ╠IâⁿλtÅ╛╲   Hì}░ΦÇ■λλδτHâ°☺v∟╛╲   Hì}░HëEá
Φf■λλHïEáHâΦ☻δ▐AÇΣ☺t↨╛“   Hì}░ΦH■λλIλ╔☼ä@λλλAÇ■☺A╛♥   Iâ┘ Mìa☺M9
⌠r¶╛“   Hì}░Iâ╞♥Φ▬■λλδτ1╥╣♥   Lë╚H≈±Hà╥A☼ö╞Θⁿ■λλHì}░Φ≥²λλHì}░Φ╛²
λλΘσ■λλ1÷Hì}░Φ┘²λλΘG■λλHâ─8ë╪[A╲A]A^A_]├╠Hì♣╪↓  ├☼┐└à└x←Ië╩☼♣H=☺
≡λλs☺├≈╪ë♣║↓  jλX∙├ï♣⌂▬  δφH┴Φ0δ•H┴Φ ☼╖└f=λ☼sσIë╩☼♣r╙├Aë├┴Φ►%λ☼ 
 A┴δ∟A┴π↑D○╪δ┌QRëλ1└âλ⌂v“☼╜╧║┐→@ ïLJ≥ë·┴∩♠ÇΓ⁇♀Ç◘╨H┴α◘■╔u∞◘ΦH○°ZY
├U1└HëσWVSQRë┬ë├λ└☼╖¶Wë╤füß ⁿfü∙ ▄tΦfü∙ ╪t♦ë▬δ,☼╖♦Gë┴füß ⁿfü∙ ▄t
♂╟♠²λ  â╚λδ☼┴Γ◙ìä☻ $áⁿë♠ìC☻ZY[^_]├f☼▼D  Éâ♪▄↑  ♦÷♣맠 ♦t♪@☼╢╧λ§ì
♣  δ°╠ï♣ö§  ☼♣·☼☺∟%Ü→@ ⌠δ²        f☼▼D  Énodll◙ KernelBase.dll ☺
└☺└☺└☺└☻α☻α☻α☻α☻α♥≡♥≡♥≡♥≡♥≡♦°♦°♦°♦°♦°♣ⁿ♣ⁿ♣ⁿ♣ⁿ♣ⁿ♣ⁿÉÉ☼▼D  ⁇♣ExitPr
ocess æ☺FreeEnvironmentStringsW ╜☺GetCommandLineW ‼☻GetEnvironme
ntStringsW  ╘☻GetStdHandle  ╫♣SetDefaultDllDirectories  ▼•WriteF
ile ░←          ░→  ►                       ☼▼@ °→      ♠←      
←      2←      L←      ╲←      x←              É☼▼Ç    É╬ ☺&τ☺╬
 ☺☺⌂╬ üÇÇ►f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼
ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä   
  f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.
☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä 
    f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     
f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼
ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä   
  f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.
☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä 
    f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     
f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼
ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä   
  f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.
☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä 
    f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     
f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     f.☼▼ä     ☼▼@ 
  @             °→      ♠←       ←      2←      L←      ╲←      
x←                                                              
See also `build/dump -xd o/tiny/examples/life.com.dbg | less` assembly
and our linker script [ape/ape.lds] which glues the binaries together.

10
ape/ape.S

@ -45,11 +45,10 @@
#include "libc/nexgen32e/vidya.h"
#include "libc/nt/pedef.h"
#include "libc/sysv/consts/prot.h"
.yoink __FILE__
.yoink "NOTICE"
.section .head,"ax",@progbits
/ Common Sections.
.source "NOTICE"
.source "ape/ape.S"
.source "ape/ape.lds"
.section .text,"ax",@progbits
.align __SIZEOF_POINTER__
.previous
@ -69,6 +68,7 @@ cstr: .endobj cstr,globl,hidden # ←for gdb readibility
.section .sort.rodata.real.str1.1,"aMS",@progbits
rlstr: .endobj rlstr,globl,hidden # for gdb readibility
.previous
.section .head,"ax",@progbits
/*
@ -1932,4 +1932,4 @@ __data_start:
.hidden __piro_start
.end



130
ape/ape.lds

@ -105,7 +105,7 @@
strip input.com.dbg # remove all symbols
strip -S input.com.dbg # remove debug info only
make CPPFLAGS=-DNDEBUG # remove asserts (prod)
make CPPFLAGS=-DIM_FEELING_NAUGHTY # remove legal notices
make CPPFLAGS=-DIM_FEELING_NAUGHTY # remove legal embeddings
The Makefile build is also configured to always produce a .map file
when building each program, which provides further details.
@ -333,9 +333,11 @@ SECTIONS {
/*BEGIN: Read only data that needn't be mapped after initialization */
/* Legal Notices */
#ifndef IM_FEELING_NAUGHTY
KEEP(*(.commentprologue))
KEEP(*(.comment))
KEEP(*(.commentepilogue))
#endif
/* Windows DLL Import Directory */
KEEP(*(.idata.ro));
@ -563,7 +565,7 @@ ZIPCONST(v_zip_commentsize, _edata - __zip_end - kZipCdirHdrMinSize);
X = (X + (Y >> 010) & 0xFF) * PHI; \
X = (X + (Y >> 020) & 0xFF) * PHI; \
X = (X + (Y >> 030) & 0xFF) * PHI
#define BOOP(X) \
#define CHURN(X) \
XORSHIFT(uuid1_, X); \
KMH(uuid1_, X); \
XORSHIFT(uuid2_, X); \
@ -572,68 +574,68 @@ ZIPCONST(v_zip_commentsize, _edata - __zip_end - kZipCdirHdrMinSize);
HIDDEN(uuid1_ = 88172645463325252);
HIDDEN(uuid2_ = 88172645463325252);
BOOP(.Lape.bss.align);
BOOP(.Lape.bss.filesz);
BOOP(.Lape.bss.memsz);
BOOP(.Lape.bss.offset);
BOOP(.Lape.bss.paddr);
BOOP(.Lape.data.align);
BOOP(.Lape.data.filesz);
BOOP(.Lape.data.memsz);
BOOP(.Lape.data.offset);
BOOP(.Lape.data.paddr);
BOOP(.Lape.data.rva);
BOOP(.Lape.data.vaddr);
BOOP(.Lape.elf.entry);
BOOP(.Lape.elf.phnum);
BOOP(.Lape.elf.phoff);
BOOP(.Lape.elf.shnum);
BOOP(.Lape.elf.shoff);
BOOP(.Lape.elf.shstrndx);
BOOP(.Lape.macho.end);
BOOP(.Lape.note);
BOOP(.Lape.note.align);
BOOP(.Lape.note.end);
BOOP(.Lape.note.filesz);
BOOP(.Lape.note.memsz);
BOOP(.Lape.note.offset);
BOOP(.Lape.note.paddr);
BOOP(.Lape.note.vaddr);
BOOP(.Lape.pe.offset);
BOOP(.Lape.pe.optsz);
BOOP(.Lape.pe.sections);
BOOP(.Lape.pe.sections_end);
BOOP(.Lape.pe.shnum);
BOOP(.Lape.phdrs.end);
BOOP(.Lape.ram.align);
BOOP(.Lape.ram.filesz);
BOOP(.Lape.ram.memsz);
BOOP(.Lape.ram.offset);
BOOP(.Lape.ram.paddr);
BOOP(.Lape.ram.rva);
BOOP(.Lape.ram.vaddr);
BOOP(.Lape.rom.align);
BOOP(.Lape.rom.filesz);
BOOP(.Lape.rom.memsz);
BOOP(.Lape.rom.offset);
BOOP(.Lape.rom.paddr);
BOOP(.Lape.rom.rva);
BOOP(.Lape.rom.vaddr);
BOOP(.Lape.text.align);
BOOP(.Lape.text.filesz);
BOOP(.Lape.text.memsz);
BOOP(.Lape.text.offset);
BOOP(.Lape.text.paddr);
BOOP(.Lape.text.rva);
BOOP(.Lape.text.vaddr);
BOOP(ADDR(.bss));
BOOP(WinMain);
BOOP(_start);
BOOP(ape.macho);
BOOP(ape.mz);
BOOP(ape.pe);
BOOP(ape.phdrs);
BOOP(v_ape_realsectors);
CHURN(.Lape.bss.align);
CHURN(.Lape.bss.filesz);
CHURN(.Lape.bss.memsz);
CHURN(.Lape.bss.offset);
CHURN(.Lape.bss.paddr);
CHURN(.Lape.data.align);
CHURN(.Lape.data.filesz);
CHURN(.Lape.data.memsz);
CHURN(.Lape.data.offset);
CHURN(.Lape.data.paddr);
CHURN(.Lape.data.rva);
CHURN(.Lape.data.vaddr);
CHURN(.Lape.elf.entry);
CHURN(.Lape.elf.phnum);
CHURN(.Lape.elf.phoff);
CHURN(.Lape.elf.shnum);
CHURN(.Lape.elf.shoff);
CHURN(.Lape.elf.shstrndx);
CHURN(.Lape.macho.end);
CHURN(.Lape.note);
CHURN(.Lape.note.align);
CHURN(.Lape.note.end);
CHURN(.Lape.note.filesz);
CHURN(.Lape.note.memsz);
CHURN(.Lape.note.offset);
CHURN(.Lape.note.paddr);
CHURN(.Lape.note.vaddr);
CHURN(.Lape.pe.offset);
CHURN(.Lape.pe.optsz);
CHURN(.Lape.pe.sections);
CHURN(.Lape.pe.sections_end);
CHURN(.Lape.pe.shnum);
CHURN(.Lape.phdrs.end);
CHURN(.Lape.ram.align);
CHURN(.Lape.ram.filesz);
CHURN(.Lape.ram.memsz);
CHURN(.Lape.ram.offset);
CHURN(.Lape.ram.paddr);
CHURN(.Lape.ram.rva);
CHURN(.Lape.ram.vaddr);
CHURN(.Lape.rom.align);
CHURN(.Lape.rom.filesz);
CHURN(.Lape.rom.memsz);
CHURN(.Lape.rom.offset);
CHURN(.Lape.rom.paddr);
CHURN(.Lape.rom.rva);
CHURN(.Lape.rom.vaddr);
CHURN(.Lape.text.align);
CHURN(.Lape.text.filesz);
CHURN(.Lape.text.memsz);
CHURN(.Lape.text.offset);
CHURN(.Lape.text.paddr);
CHURN(.Lape.text.rva);
CHURN(.Lape.text.vaddr);
CHURN(ADDR(.bss));
CHURN(WinMain);
CHURN(_start);
CHURN(ape.macho);
CHURN(ape.mz);
CHURN(ape.pe);
CHURN(ape.phdrs);
CHURN(v_ape_realsectors);
ASSERT(ape.mz == IMAGE_BASE_VIRTUAL, "linker panic");
ASSERT((DEFINED(__init_bss_end) ? __init_bss_end : 0) % __SIZEOF_POINTER__ == 0,

43
ape/ape.mk

@ -15,38 +15,37 @@
PKGS += APE
DEFAULT_COPTS += -mno-red-zone
DEFAULT_LDFLAGS += -z max-page-size=0x1000
APELINK = ACTION=LINK.ape $(LINK) $(LINKARGS) $(OUTPUT_OPTION) && $(STRIP) -X $@ && $(GZ) $(ZFLAGS) -f $@.map
APE = $(APE_DEPS) \
$(APE_OBJS) \
o/$(MODE)/ape/ape.lds
APE_FILES := \
$(wildcard ape/*.*)
APE_HDRS = \
$(filter %.h,$(APE_FILES))
APELINK = \
ACTION=LINK.ape \
$(LINK) \
$(LINKARGS) \
$(OUTPUT_OPTION) && \
$(STRIP) \
-X $@ && \
$(GZ) \
$(ZFLAGS) \
-f $@.map
APE_SRCS = \
$(filter %.S,$(APE_FILES))
APE_OBJS = \
$(APE_SRCS:%=o/$(MODE)/%.zip.o) \
$(APE_SRCS:%.S=o/$(MODE)/%.o)
APE_DEPS = \
$(APE_LIB)
DEFAULT_COPTS += -mno-red-zone
DEFAULT_LDFLAGS += -z max-page-size=0x1000
APE_CHECKS = \
$(APE_HDRS:%=o/%.ok)
APE_FILES := $(wildcard ape/*.*)
APE_HDRS = $(filter %.h,$(APE_FILES))
APE_SRCS = $(filter %.S,$(APE_FILES))
APE_OBJS = $(APE_SRCS:%.S=o/$(MODE)/%.o)
APE_DEPS = $(APE_LIB)
APE_CHECKS = $(APE_HDRS:%=o/%.ok)
o/%.com: o/%.com.dbg
@ACTION=OBJCOPY.ape TARGET=$@ build/do $(OBJCOPY) -SO binary $< $@
o/ape/idata.inc: ape/idata.h ape/relocations.h
o/ape/idata.inc: \
ape/idata.h \
ape/relocations.h
$(APE_OBJS): $(BUILD_FILES) \
ape/ape.mk

2
ape/lib/apelib.mk

@ -19,6 +19,8 @@ APE_LIB_A_OBJS = \
$(APE_LIB_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(APE_LIB_A_SRCS_C:%.c=o/$(MODE)/%.o) \
$(APE_LIB_A_SRCS:%=o/$(MODE)/%.zip.o) \
o/$(MODE)/ape/ape.lds.zip.o \
o/$(MODE)/ape/ape.S.zip.o \
o/$(MODE)/NOTICE.zip.o
APE_LIB_A_CHECKS = $(APE_LIB_A_HDRS:%=o/$(MODE)/%.ok)

2
ape/lib/bootdr.S

@ -20,7 +20,7 @@
#include "ape/macros.h"
#include "ape/notice.inc"
.section .real,"ax",@progbits
.yoink __FILE__
.source __FILE__
.code16
/ Resets personal computer.

2
ape/lib/e820map.S

@ -22,7 +22,7 @@
#include "ape/macros.h"
#include "ape/notice.inc"
.section .real,"ax",@progbits
.yoink __FILE__
.source __FILE__
.code16
.globl e820map

2
ape/lib/g_pml4t.S

@ -22,7 +22,7 @@
#include "ape/macros.h"
#include "ape/notice.inc"
.section .real,"ax",@progbits
.yoink __FILE__
.source __FILE__
.code16
.globl g_pml4t

2
ape/lib/g_ptsp.S

@ -22,7 +22,7 @@
#include "ape/macros.h"
#include "ape/notice.inc"
.section .real,"ax",@progbits
.yoink __FILE__
.source __FILE__
.code16
.globl g_ptsp

2
ape/lib/kbiosdataarea.S

@ -22,7 +22,7 @@
#include "ape/macros.h"
#include "ape/notice.inc"
.section .real,"ax",@progbits
.yoink __FILE__
.source __FILE__
.code16
.globl kBiosDataArea

4
build/definitions.mk

@ -51,7 +51,7 @@ CP ?= /bin/cp -f
RM ?= /bin/rm -f
SED ?= /bin/sed
MKDIR ?= /bin/mkdir -p
TAGS ?= ctags
TAGS ?= /usr/bin/ctags # emacs source builds or something breaks it
ARFLAGS = rcsD
TAGSFLAGS ?= -e -a --if0=no --langmap=c:.c.h.i --line-directives=yes
SILENT ?= 1
@ -74,6 +74,7 @@ NM = o/third_party/gcc/bin/x86_64-linux-musl-nm
GCC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
STRIP = o/third_party/gcc/bin/x86_64-linux-musl-strip
OBJCOPY = o/third_party/gcc/bin/x86_64-linux-musl-objcopy
OBJDUMP = o/third_party/gcc/bin/x86_64-linux-musl-objdump
ADDR2LINE = o/third_party/gcc/bin/x86_64-linux-musl-addr2line
COMMA := ,
@ -87,6 +88,7 @@ BLAH1 := $(shell build/zipobj 2>/dev/null)
BLAH2 := $(shell build/package 2>/dev/null)
export ADDR2LINE
export OBJDUMP
export CCNAME
export CCVERSION
export CP

21
build/objdump

@ -0,0 +1,21 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# GNU Disassembly Veneer
#
# DESCRIPTION
#
# This script wraps normal objdump commands that're transparently
# passed-through.
#
# EXAMPLE
#
# build/objdump -xd o/tiny/examples/life.com.dbg
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
fi
exec o/third_party/gcc/bin/x86_64-linux-musl-objdump "$@"

2
dsp/core/mulaw.S

@ -61,4 +61,4 @@ mulaw: .leafprologue
mov %edx,%eax
jmp 3b
.endfn mulaw,globl
.yoink __FILE__
.source __FILE__

2
dsp/core/sad16x8n.S

@ -38,4 +38,4 @@ sad16x8n:
jnz 0b
1: .leafepilogue
.endfn sad16x8n,globl,hidden
.yoink __FILE__
.source __FILE__

2
dsp/mpeg/clamp4int256-core.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
clamp4int256$core:
.leafprologue

2
dsp/tty/windex-avx2.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Returns index of minimum uint16 in array.
/

2
dsp/tty/windex-sse4.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Returns index of minimum positive int16 in array.
/

2
dsp/tty/windex.S

@ -19,7 +19,7 @@
*/
#include "libc/nexgen32e/x86feature.h"
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Dispatches to fastest windex() implementation.
.initbss 300,_init_windex

0
examples/package/README.md

63
examples/package/lib/lib.mk

@ -0,0 +1,63 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
#
# SYNOPSIS
#
# Your package static library build config
#
# DESCRIPTION
#
# Your library doesn't have a main() function and can be compromised
# of sources written in multiple languages.
PKGS += EXAMPLES_PACKAGE_LIB
EXAMPLES_PACKAGE_LIB_ARTIFACTS += EXAMPLES_PACKAGE_LIB_A
EXAMPLES_PACKAGE_LIB = $(EXAMPLES_PACKAGE_LIB_A_DEPS) $(EXAMPLES_PACKAGE_LIB_A)
EXAMPLES_PACKAGE_LIB_A = o/$(MODE)/examples/package/lib/lib.a
EXAMPLES_PACKAGE_LIB_A_HDRS = $(filter %.h,$(EXAMPLES_PACKAGE_LIB_A_FILES))
EXAMPLES_PACKAGE_LIB_A_SRCS_S = $(filter %.S,$(EXAMPLES_PACKAGE_LIB_A_FILES))
EXAMPLES_PACKAGE_LIB_A_SRCS_C = $(filter %.c,$(EXAMPLES_PACKAGE_LIB_A_FILES))
EXAMPLES_PACKAGE_LIB_A_CHECKS = $(EXAMPLES_PACKAGE_LIB_A).pkg
EXAMPLES_PACKAGE_LIB_A_FILES := \
$(wildcard examples/package/lib/*) \
$(wildcard examples/package/lib/thunks/*)
EXAMPLES_PACKAGE_LIB_A_SRCS = \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_S) \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_C)
EXAMPLES_PACKAGE_LIB_A_OBJS = \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(EXAMPLES_PACKAGE_LIB_A_SRCS_C:%.c=o/$(MODE)/%.o) \
$(EXAMPLES_PACKAGE_LIB_A_SRCS:%=o/$(MODE)/%.zip.o)
EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS = \
LIBC_STDIO \
LIBC_STUBS
EXAMPLES_PACKAGE_LIB_A_DEPS := \
$(call uniq,$(foreach x,$(EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS),$($(x))))
$(EXAMPLES_PACKAGE_LIB_A): \
examples/package/lib/ \
$(EXAMPLES_PACKAGE_LIB_A).pkg \
$(EXAMPLES_PACKAGE_LIB_A_OBJS)
$(EXAMPLES_PACKAGE_LIB_A).pkg: \
$(EXAMPLES_PACKAGE_LIB_A_OBJS) \
$(foreach x,$(EXAMPLES_PACKAGE_LIB_A_DIRECTDEPS),$($(x)_A).pkg)
$(EXAMPLES_PACKAGE_LIB_A_OBJS): examples/package/lib/lib.mk
EXAMPLES_PACKAGE_LIB_LIBS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)))
EXAMPLES_PACKAGE_LIB_SRCS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_SRCS))
EXAMPLES_PACKAGE_LIB_HDRS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_HDRS))
EXAMPLES_PACKAGE_LIB_BINS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_BINS))
EXAMPLES_PACKAGE_LIB_CHECKS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_CHECKS))
EXAMPLES_PACKAGE_LIB_OBJS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_OBJS))
EXAMPLES_PACKAGE_LIB_TESTS = $(foreach x,$(EXAMPLES_PACKAGE_LIB_ARTIFACTS),$($(x)_TESTS))
.PHONY: o/$(MODE)/examples/package/lib
o/$(MODE)/examples/package/lib: $(EXAMPLES_PACKAGE_LIB_CHECKS)

6
examples/package/lib/myasm.S

@ -0,0 +1,6 @@
#include "libc/macros.h"
MyAsm: .leafprologue
call MyPrint2
.leafepilogue
.endfn MyAsm,globl

10
examples/package/lib/myprint.c

@ -0,0 +1,10 @@
#include "examples/package/lib/myprint.h"
#include "libc/stdio/stdio.h"
void MyPrint(const char *s) {
MyAsm(s);
}
void MyPrint2(const char *s) {
fputs(s, stdout);
}

11
examples/package/lib/myprint.h

@ -0,0 +1,11 @@
#ifndef COSMOPOLITAN_EXAMPLES_PACKAGE_LIB_MYPRINT_H_
#define COSMOPOLITAN_EXAMPLES_PACKAGE_LIB_MYPRINT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
void MyPrint(const char *);
void MyAsm(const char *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_EXAMPLES_PACKAGE_LIB_MYPRINT_H_ */

33
examples/package/new.sh

@ -0,0 +1,33 @@
#!/bin/sh
#
# SYNOPSIS
#
# Creates new package in repository.
#
# EXAMPLE
#
# examples/package/new.sh com/github/user/project
DIR=${1:?need directory arg}
VAR=$(echo "$DIR" | tr a-z A-Z | tr / _)
BASENAME=${DIR##*/}
FILENAME="$DIR/$BASENAME"
MAKEFILE="$DIR/$BASENAME.mk"
if [ -d "$DIR" ]; then
echo "already exists: $DIR" >&2
exit 1
fi
mkdir -p "$DIR" &&
cp -R examples/package/new/* "$DIR" &&
find "$DIR" -type f |
xargs sed -i -e "
s/EXAMPLES_PACKAGE/$VAR/g
s/examples\/package\/package/$FILENAME/g
s/examples\/package/$DIR/g
" &&
sed -i -e "
/#-φ-examples\/package\/new\.sh/i\
include $MAKEFILE
" Makefile

74
examples/package/package.mk

@ -0,0 +1,74 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
#
# SYNOPSIS
#
# Your package build config for executable programs
#
# DESCRIPTION
#
# We assume each .c file in this directory has a main() function, so
# that it becomes as easy as possible to write lots of tiny programs
#
# EXAMPLE
#
# make o//examples/package
# o/examples/package/program.com
PKGS += EXAMPLES_PACKAGE
# Reads into memory the list of files in this directory.
EXAMPLES_PACKAGE_FILES := $(wildcard examples/package/*)
# Defines sets of files without needing further iops.
EXAMPLES_PACKAGE_SRCS = $(filter %.c,$(EXAMPLES_PACKAGE_FILES))
EXAMPLES_PACKAGE_HDRS = $(filter %.h,$(EXAMPLES_PACKAGE_FILES))
EXAMPLES_PACKAGE_COMS = $(EXAMPLES_PACKAGE_OBJS:%.o=%.com)
# Remaps source file names to object names.
# Also asks a wildcard rule to automatically run tool/build/zipobj.c
EXAMPLES_PACKAGE_OBJS = \
$(EXAMPLES_PACKAGE_SRCS:%.c=o/$(MODE)/%.o) \
$(EXAMPLES_PACKAGE_SRCS:%=o/$(MODE)/%.zip.o)
EXAMPLES_PACKAGE_BINS = \
$(EXAMPLES_PACKAGE_COMS) \
$(EXAMPLES_PACKAGE_COMS:%=%.dbg)
# Lists packages whose symbols are or may be directly referenced here.
# Note that linking stubs is always a good idea due to synthetic code.
EXAMPLES_PACKAGE_DIRECTDEPS = \
EXAMPLES_PACKAGE_LIB \
LIBC_STDIO \
LIBC_STUBS \
LIBC_TINYMATH
# Evaluates the set of transitive package dependencies.
EXAMPLES_PACKAGE_DEPS := \
$(call uniq,$(foreach x,$(EXAMPLES_PACKAGE_DIRECTDEPS),$($(x))))
# Invalidates objects in this package when this makefile is edited
$(EXAMPLES_PACKAGE_OBJS): examples/package/vizlib.mk
# Asks packager to index symbols and validate their relationships.
# @see tool/build/package.c
# @see build/rules.mk
o/$(MODE)/examples/package/build.pkg: \
$(EXAMPLES_PACKAGE_OBJS) \
$(foreach x,$(EXAMPLES_PACKAGE_DIRECTDEPS),$($(x)_A).pkg)
# Specifies how to build programs as ELF binaries with DWARF debug info.
# @see build/rules.mk for definition of rule that does .com.dbg -> .com
o/$(MODE)/examples/package/%.com.dbg: \
$(EXAMPLES_PACKAGE_DEPS) \
o/$(MODE)/examples/package/package.pkg \
o/$(MODE)/examples/package/%.o \
$(CRT) \
$(APE)
-@$(APELINK)
# Creates target that builds everything in this package and subpackages.
.PHONY: o/$(MODE)/examples/package
o/$(MODE)/examples/package: \
o/$(MODE)/examples/package/lib \
$(EXAMPLES_PACKAGE_BINS) \
$(EXAMPLES_PACKAGE_CHECKS)

6
examples/package/program.c

@ -0,0 +1,6 @@
#include "examples/package/lib/myprint.h"
int main(int argc, char *argv[]) {
MyPrint("welcome to your package");
return 0;
}

35
examples/raw-linux-hello.S → examples/tiny-raw-linux-tutorial.S

@ -19,31 +19,42 @@
*/
#include "libc/macros.h"
/ Raw Linux Assembly Binary Tutorial
/ Tiny Raw Linux Binary Tutorial
/
/ i.e. how to not use cosmopolitan runtimes at all
/ cosmopolitan basically abstracts this
/ except for all major platforms
/
/ make o//examples/raw-linux-hello.elf
/ o//examples/raw-linux-hello.elf # about 6kb
/ make o//examples/raw-linux-hello.elf
/ o/examples/raw-linux-hello.elf # about 6kb
/
/ Next consider doing it in C with fancy build tuning
/ Next try C but with fancy build tuning
/
/ make -j8 -O \
/ MODE=tiny \
/ LDFLAGS=-s \
/ CPPFLAGS=-DSUPPORT_VECTOR=0b00000001 \
/ o/tiny/examples/hello2.elf
/ o/tiny/examples/hello2.elf # about 8kb
/ make -j8 -O \
/ MODE=tiny \
/ LDFLAGS+=-s \
/ CPPFLAGS+=-DIM_FEELING_NAUGHTY \
/ CPPFLAGS+=-DSUPPORT_VECTOR=0b00000001 \
/ o/tiny/examples/hello2.elf
/ o/tiny/examples/hello2.elf # about 8kb
/
/ @param rsp is [n,argv..argvₙ,0,envp..,0,auxv..,0,..]
/ @see also glibc static binaries which start at 800kb!!!
/ @see also go where interfaces sadly disempower ld prune
/ @see also the stl where bad linkage is due to tech debt
/ @see libc/macros-cpp.inc forthe getstr macro definition
/ @note libc/elf/elf.lds can be tinier with page align off
/ @note gas is more powerful than nasm due to rms notation
/ @noreturn
_start: mov $12,%rdx # arg no. 3 is length
getstr "hello world\n",%rsi,%esi # arg no. 2 is memory
mov $1,%edi # arg no. 1 is stdout
mov $1,%eax # write()
syscall # see libc/sysv/syscalls.sh
syscall # libc/sysv/syscalls.sh
mov $0,%edi # arg no. 1 is success status
mov $0xE7,%eax # exit_group()
syscall
syscall # context switch
0: rep nop # basic blockading
jmp 0b
.endfn _start,globl
.source __FILE__

2
libc/alg/djbsort-avx2.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
.p2align 4
minmax_vector:

2
libc/calls/g_ntstartupinfo_init.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
.init.start 400,_init_g_ntstartupinfo
ezlea g_ntstartupinfo,cx

2
libc/calls/g_ntsysteminfo_init.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
.init.start 400,_init_g_ntsysteminfo
ezlea g_ntsysteminfo,cx

2
libc/calls/getntsyspath.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Obtains WIN32 magic path, e.g. GetTempPathA.
/

1
libc/calls/hefty/mkntcmdline.c

@ -26,6 +26,7 @@
#include "libc/nexgen32e/hascharacter.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/errfuns.h"

1
libc/calls/hefty/mkntenvblock.c

@ -23,6 +23,7 @@
#include "libc/macros.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/sysv/errfuns.h"
/**

2
libc/calls/ktmppath.S

@ -40,4 +40,4 @@ kTmpPath:
call __getntsyspath
.init.end 300,_init_kTmpPath
.yoink __FILE__
.source __FILE__

1
libc/calls/mkntpath.ncabi.c

@ -23,6 +23,7 @@
#include "libc/calls/internal.h"
#include "libc/conv/conv.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/sysv/errfuns.h"
/**

2
libc/calls/onntconsoleevent_init.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
.init.start 300,_init_onntconsoleevent
ezlea onntconsoleevent$nt,cx

2
libc/calls/onwincrash_init.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
.init.start 300,_init_onwincrash
pushpop 1,%rcx

2
libc/calls/pipe-sysv.S

@ -19,7 +19,7 @@
*/
#include "libc/dce.h"
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Creates file descriptors for IPC.
/

2
libc/calls/setegid.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Sets effective group ID.
/

2
libc/calls/seteuid.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Sets effective user ID.
/

2
libc/calls/sigenter.S

@ -19,7 +19,7 @@
*/
#include "libc/calls/internal.h"
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ System Five signal handler.
/

2
libc/calls/thunks/ftruncate-sysv.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Directly calls ftruncate() impl on host o/s if available.
ftruncate$sysv:

2
libc/calls/thunks/gettemppatha-flunk.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Calls GetTempPathA() w/ different API.
/

2
libc/calls/thunks/lseek-sysv.S

@ -19,7 +19,7 @@
*/
#include "libc/dce.h"
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Directly calls lseek() impl on host o/s if available.
lseek$sysv:

2
libc/calls/thunks/mmap-sysv.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Directly calls mmap() on system five host o/s.
mmap$sysv:

2
libc/calls/thunks/onntconsoleevent.S

@ -19,7 +19,7 @@
*/
#include "libc/macros.h"
.text.windows
.yoink __FILE__
.source __FILE__
onntconsoleevent$nt:
ezlea onntconsoleevent,ax

2
libc/calls/thunks/onwincrash.S

@ -19,7 +19,7 @@
*/
#include "libc/macros.h"
.text.windows
.yoink __FILE__
.source __FILE__
onwincrash$nt:
ezlea onwincrash,ax

2
libc/calls/thunks/pread-sysv.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Directly calls pread() impl on host o/s if available.
pread$sysv:

2
libc/calls/thunks/preadv-sysv.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Directly calls preadv() impl on host o/s if available.
preadv$sysv:

2
libc/calls/thunks/pwrite-sysv.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Directly calls pwrite() impl on host o/s if available.
pwrite$sysv:

2
libc/calls/thunks/pwritev-sysv.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Directly calls pwritev() impl on host o/s if available.
pwritev$sysv:

2
libc/calls/thunks/truncate-sysv.S

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Directly calls truncate() impl on host o/s if available.
truncate$sysv:

2
libc/crt/crt.S

@ -22,7 +22,7 @@
#include "libc/notice.inc"
#include "libc/runtime/internal.h"
.section .start,"ax",@progbits
.yoink __FILE__
.source __FILE__
/ System Five userspace program entrypoint.
/

2
libc/fmt/kerrnonames.S

@ -19,7 +19,7 @@
*/
#include "libc/notice.inc"
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
/ Embeds ASCII names for errno constants into binary.
/

2
libc/fmt/stoa.c

@ -26,6 +26,8 @@
#include "libc/nexgen32e/tinystrlen.h"
#include "libc/str/internal.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/str/tpencode.h"
#include "libc/unicode/unicode.h"
forceinline unsigned long tpiencode(wint_t wc) {

23
libc/integral/c.inc

@ -983,7 +983,7 @@ typedef uint64_t uintmax_t;
/**
* Pulls another module, by symbol, into linkage.
* The nop itself is discarded by the linker.
* @note nop is discarded by ape/ape.lds
*/
#define YOINK(SYMBOL) \
do { \
@ -996,11 +996,30 @@ typedef uint64_t uintmax_t;
: "X"(SYMBOL)); \
} while (0)
/**
* Pulls another module into linkage from top-level scope.
* @note nop is discarded by ape/ape.lds
*/
#define STATIC_YOINK(SYMBOLSTR) \
asm(".pushsection .yoink\n\tnop\t\"" SYMBOLSTR "\"\n\t.popsection")
/**
* Pulls source file into ZIP portion of binary.
* @see build/rules.mk which defines the wildcard build rule %.zip.o
*/
#ifndef IM_FEELING_NAUGHTY
#define STATIC_YOINK_SOURCE(PATH) STATIC_YOINK(PATH)
#else
#define STATIC_YOINK_SOURCE(PATH)
#endif
/**
* Pulls source code of object being compiled.
* @note automates better compliance with spirit of gpl terms
* @note headers need to call STATIC_YOINK_SOURCE() manually
*/
#ifdef __SAUCE__
STATIC_YOINK(__SAUCE__);
STATIC_YOINK_SOURCE(__SAUCE__); /* see build/definitions.mk */
#endif
#ifndef __cplusplus

2
libc/log/loglevel.S

@ -19,7 +19,7 @@
*/
#include "libc/log/log.h"
#include "libc/macros.h"
.yoink __FILE__
.source __FILE__
.bss
.align 4