Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#######
#
# E-scripts on the "anatomy" of compiled C programs
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
# An introduction to eev can be found here:
#
#   (find-eev-quick-intro)
#   http://angg.twu.net/eev-intros/find-eev-quick-intro.html
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/e/anatocc.e>
#           or at <http://angg.twu.net/e/anatocc.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.emacs[.html]>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######





# «.glibc»			(to "glibc")
# «.gcc_libc_docs»		(to "gcc_libc_docs")
# «.asm_in_gcc»			(to "asm_in_gcc")
# «.hello-world-in-asm»		(to "hello-world-in-asm")
# «.elf-kickers»		(to "elf-kickers")
# «.elf-kickers-deb-src»	(to "elf-kickers-deb-src")
# «.c-to-EsSo»			(to "c-to-EsSo")
# «.objdump»			(to "objdump")
# «.binutils»			(to "binutils")
# «.easynasm»			(to "easynasm")
# «.nasm_crim1»			(to "nasm_crim1")
# «.gdb_and_C_types»		(to "gdb_and_C_types")
# «.cdecl»			(to "cdecl")
# «.pointer-to-function»	(to "pointer-to-function")
# «.c_eval»			(to "c_eval")
# «.dlopen»			(to "dlopen")
# «.dlopen-gdb»			(to "dlopen-gdb")
# «.gcc-v»			(to "gcc-v")
# «.libvforkwrap»		(to "libvforkwrap")
# «.LD_PRELOAD»			(to "LD_PRELOAD")
# «.gcc_source»			(to "gcc_source")
# «.glibc-src»			(to "glibc-src")
# «.ld.so»			(to "ld.so")
# «.regexps»			(to "regexps")
# «.system»			(to "system")
# «.edrxroot»			(to "edrxroot")
# «.biew»			(to "biew")
# «.dietlibc»			(to "dietlibc")
# «.dietlibc-git»		(to "dietlibc-git")
# «.dietlibc-deb-src»		(to "dietlibc-deb-src")
# «.uclibc»			(to "uclibc")
# «.uclibc-upstream»		(to "uclibc-upstream")
# «.uclibc-deb-src»		(to "uclibc-deb-src")
# «.newlib-deb-src»		(to "newlib-deb-src")
# «.newlib-upstream»		(to "newlib-upstream")
# «.tcc»			(to "tcc")
# «.endianness»			(to "endianness")
# «.tcc-deb-src»		(to "tcc-deb-src")
# «.nasm-upstream»		(to "nasm-upstream")
# «.fasm»			(to "fasm")
# «.K-and-R»			(to "K-and-R")
# «.K-and-R-old»		(to "K-and-R-old")
# «.stabs»			(to "stabs")
# «.eckelcpp»			(to "eckelcpp")
# «.warning»			(to "warning")
# «.alignment»			(to "alignment")
# «.stackdemo»			(to "stackdemo")
# «.updating-glibc»		(to "updating-glibc")
# «.UnderC»			(to "UnderC")
# «.c4»				(to "c4")
# «.lcc»			(to "lcc")
# «.small-c-iso»		(to "small-c-iso")
# «.readelf-runpath»		(to "readelf-runpath")
# «.dungeon-generator»		(to "dungeon-generator")





#####
#
# glibc
# 2019sep20
#
#####

# «glibc» (to ".glibc")
# (find-zsh "installeddebs | sort | grep glibc")
# (find-zsh "availabledebs | sort | grep glibc")
# (find-sh "apt-cache showsrc glibc")
# (find-sh "apt-cache showsrc glibc | grep dbg")

https://packages.debian.org/source/sid/glibc

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
apti glibc-source
apti libc6-dbg

# (find-status   "glibc-source")
# (find-vldifile "glibc-source.list")
# (find-udfile   "glibc-source/")
# (find-status   "libc6-dbg")
# (find-vldifile "libc6-dbg.list")
# (find-vldifile "libc6-dbg:amd64.list")
# (find-udfile   "libc6-dbg/")




#####
#
# gcc/libc docs
# 2001feb06 / 2012feb23
#
#####

# «gcc_libc_docs»  (to ".gcc_libc_docs")
# The libc info docs are MUCH better than the manpages.
# (find-node "(libc)Top")
# (find-node "(gcc)Top")
#*
zcatinfo /usr/share/info/gcc > /tmp/gcc.info
zcatinfo /usr/share/info/libc > /tmp/libc.info
#*
# (find-fline "/tmp/gcc.info")
# (find-fline "/tmp/libc.info")

# (find-status   "glibc-doc")
# (find-vldifile "glibc-doc.list")
# (find-udfile   "glibc-doc/")
# (find-status   "glibc-doc-reference")
# (find-vldifile "glibc-doc-reference.list")
# (find-udfile   "glibc-doc-reference/")
# (find-status   "gcc-doc")
# (find-vldifile "gcc-doc.list")
# (find-udfile   "gcc-doc/")



apti glibc-doc-reference




#####
#
# asm in gcc
# 2001feb08
#
#####

# «asm_in_gcc»  (to ".asm_in_gcc")
# (find-htetfile "Assembly-HOWTO.gz")
# (find-htetfile "Assembly-HOWTO.gz" "crt1.S")
# (find-htetfile "Assembly-HOWTO.gz" "docs for GCC Inline Asm")
# (find-node "(gcc)C Extensions")
# (find-node "(gcc)Extended Asm")
# (find-node "(gcc)Extended Asm" "with no outputs")
# (find-node "(as)Index")
# (find-node "(as)Pseudo Ops")
# (find-node "(as)Syntax")
# (find-node "(as)Preprocessing" "#APP")
# (find-fline "/tmp/x.s")
# (find-fline "/tmp/y.s")
# (find-k22file "arch/i386/")
#*
cd /tmp/
cat > x.c <<'---'
int foo[] = {1, 2};
int bar() { return quux(3); }
---
gcc -S x.c
cat x.s
#*
cat > y.c <<'---'
int dummy() {
  /* __asm__(".data" : ".byte 0x12, 0x23" : ".text"); */
  __asm__("\n.data\n"
	  "\t.byte 0x12, 0x23\n"
	  ".text\n"
	  ::);
}
---
gcc -S y.c
cat y.s
#*

# (find-node "(as)Infix Ops")
# (find-node "(as)Preprocessing")
# (find-node "(gasp)Overview")
# (find-node "(gcc)Overall Options" "`FILE.S'")




#####
#
# "hello, world" in asm
# 2005out18 (thx to debiantux)
#
#####

# «hello-world-in-asm»  (to ".hello-world-in-asm")
# (find-htetfile "Assembly-HOWTO.gz" "6.2.3. GAS (hello.S)")
#*
rm -Rv ~/usrc/asmtest/
mkdir  ~/usrc/asmtest/
cd     ~/usrc/asmtest/
cat > hello.S <<'%%%'
.data                                   # section declaration
msg:
        .ascii  "Hello, world!\n"       # our dear string
        len = . - msg                   # length of our dear string
.text                                   # section declaration
                        # we must export the entry point to the ELF
                        linker or
    .global _start      # loader. They conventionally recognize _start
    as their
                        # entry point. Use ld -e foo to override the
                        default.
_start:
# write our string to stdout
        movl    $len,%edx       # third argument: message length
        movl    $msg,%ecx       # second argument: pointer to message to
        write
        movl    $1,%ebx         # first argument: file handle (stdout)
        movl    $4,%eax         # system call number (sys_write)
        int     $0x80           # call kernel
# and exit
        movl    $0,%ebx         # first argument: exit code
        movl    $1,%eax         # system call number (sys_exit)
        int     $0x80           # call kernel
%%%

as -o hello.o hello.S
ld -s -o hello hello.o
./hello

#*



#####
#
# ELF kickers
# 2000jun20
#
#####

# «elf-kickers»  (to ".elf-kickers")
# http://www.muppetlabs.com/~breadbox/software/elfkickers.html
# https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
# (find-shttpw3 "www.muppetlabs.com/~breadbox/software/elfkickers.html")
#*
rm -Rv /usr/src/ELFkickers/
cd /usr/src/
tar -xvzf $S/ftp/ftp.muppetlabs.com/pub/software/ELFkickers.tar.gz
cd /usr/src/ELFkickers/

cd /usr/src/ELFkickers/tiny/
./factor 1232
#*

# (code-c-d "elfk" "/usr/src/ELFkickers/")
# (find-elfkfile "")
# (find-elfkfile "README")
# (find-elfkfile "tiny/")
# (find-elfkfile "tiny/factor.asm")
# (find-elfkfile "tiny/factor.asm" "dynamic:")

# (find-elfkfile "tiny/factor.asm" "")

tar -tvzf $S/ftp/ftp.muppetlabs.com/pup/software/tiny.tar.gz

# (code-c-d "muppet" "$S/http/www.muppetlabs.com/")
# (find-muppetw3 "~breadbox/software/tiny/teensy.html")
# (find-muppetw3 "~breadbox/software/tiny/home.html")
# (find-muppetfile "~breadbox/software/ELF.txt")
# (find-muppetfile "~breadbox/software/ELF.txt" "\nPART 2")

# (find-k22file "fs/binfmt_elf.c")
# (find-k22file "include/linux/elf.h")
# (find-k22file "include/linux/elfcore.h")
# (find-k22file "include/asm-i386/elf.h")
# (find-k22file "include/config/binfmt/elf.h")




#####
#
# elfkickers (from the debian sources)
# 2007oct27
#
#####

# «elf-kickers-deb-src»  (to ".elf-kickers-deb-src")
# http://ftp.debian.org/debian/pool/main/e/elfkickers/
# http://ftp.debian.org/debian/pool/main/e/elfkickers/elfkickers_2.0a-2.dsc
# http://ftp.debian.org/debian/pool/main/e/elfkickers/elfkickers_2.0a-2.diff.gz
# http://ftp.debian.org/debian/pool/main/e/elfkickers/elfkickers_2.0a.orig.tar.gz
#*
rm -Rv ~/usrc/elfkickers/
mkdir  ~/usrc/elfkickers/
cd $S/http/ftp.debian.org/debian/pool/main/e/elfkickers/
cp -v elfkickers_2.0a* ~/usrc/elfkickers/
cd     ~/usrc/elfkickers/
dpkg-source -sn -x elfkickers_2.0a-2.dsc
cd     ~/usrc/elfkickers/elfkickers-2.0a/
dpkg-buildpackage -us -uc -b -rfakeroot     |& tee odb

#*
# (find-fline "~/usrc/elfkickers/")
* (eepitch-shell)
cd ~/usrc/elfkickers/
sudo dpkg -i *.deb

#*
# (code-c-d "elfkickers" "~/usrc/elfkickers/elfkickers-2.0a/")
# (find-elfkickersfile "")
# (find-elfkickersfile "tiny/")




#####
#
# .c -> .[EsSo]
# 2000jun20 / 2021sep18
#
#####

# «c-to-EsSo»  (to ".c-to-EsSo")
# (find-gccnode "Overall Options")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -Rv /tmp/c/
mkdir  /tmp/c/
cd     /tmp/c/
cat > demo.c <<'---'
#include <stdio.h>
int main() {
  int sum, i;
  for(sum=0, i=0; i<10; ++i)
    sum += i;
  printf("Sum: %d\n", sum);
}
---
gcc -E demo.c > demo.i
gcc -S demo.c
gcc -S demo.c -g -o demog.s
gcc -c demo.c
gcc -c demo.c -g -o demog.o
gcc    demo.c -o demo -v	|& tee ogv
gcc    demo.c -o demog -g -v	|& tee ogvg

tkdiff ogv ogvg




#####
#
# objdump
# 2000jun24 / 2011dec26
#
#####

# «objdump»  (to ".objdump")
# «binutils»  (to ".binutils")
# (find-angg ".emacs" "binutils")
# (find-es "texinfo" "triggers")
# (find-status   "binutils")
# (find-vldifile "binutils.list")
# (find-udfile   "binutils/")
# (find-status   "binutils-doc")
# (find-vldifile "binutils-doc.list")
# (find-udfile   "binutils-doc/")
# (find-fline "/usr/lib/ldscripts/")

# (find-man "1 objdump")
# (find-node "(binutils)objdump")

# (find-es "fortho" "eforth")

cd /usr/src/eforth-1.0e/
objdump -Ssax eforth |& tee ~/o

# (find-fline "~/o")








#####
#
# nasm
# 2000jun23
#
#####

# (find-status "nasm")
# (find-vldifile "nasm.list")
# (find-fline "/usr/doc/nasm/")

# (find-node "(nasm)Top")
# (find-node "(nasm)Chapter 6" "`elf'")
# (find-node "(nasm)Section 8.1.1" "ELF, though, the leading underscore")
# (find-node "(nasm)Appendix A")





#####
#
# easynasm
# 2000jul06
#
#####

# «easynasm»  (to ".easynasm")
# (find-es "fortho" "perpol")
#*

rm -Rv /usr/src/easynasm/
cd /usr/src/
tar -xvzf $S/http/www.boswa.com/education/programming/easynasm.tgz
cd /usr/src/easynasm/

# (find-fline "/usr/src/easynasm/")
# (find-fline "/usr/src/easynasm/readme.txt")

./easynasm hello.asm	&& ./hello
./easynasm hi.asm	&& ./hi
./easynasm simple.asm	&& ./simple

#*





#####
#
# using nasm to write crim1 programs
# 2000jul08
#
#####

# «nasm_crim1»  (to ".nasm_crim1")
# (find-node "(nasm)Section 6.1.1" "dd label")
# (find-node "(nasm)Chapter 8" "Interfacing to 32-bit C Programs")
# (find-node "(nasm)Section 3.2" "`DB' and friends")
# (find-node "(nasm)Section 4.1.1" "%define")
# (find-node "(nasm)Section 4.2" "%macro")

cd /usr/share/info/
zcatinfo /usr/share/info/nasm > /tmp/nasm
# (find-fline "/tmp/nasm")

#*

cat > /tmp/demo.asm <<'---'
%macro d2 1
	db ((%1) - _f0) >> 8
	db ((%1) - _f0) & 0xFF
%endmacro
%define H_COL 0xFF
%define H_RSR 0xFE
%define H_CON 0xFD
%define H_TO  0xFC
%define H_AT  0xFB

%define SF_EXIT		0xFF
%define SF_PLUS		0xFE
%define SF_2DUP		0xFD

%define COUNT		_f0 + 0xFA00
%define TYPE		_f0 + 0xFA01
%define CR		_f0 + 0xFA02
%define STO		_f0 + 0xFA03
%define TOS		_f0 + 0xFA04

_f0:

AT_FOO:	db H_AT
TO_FOO:	db H_TO
FOO:	db H_CON
	dw 0x1234

SSTRGOBBLE:
	db H_COL
	d2 STO
	d2 COUNT
	db SF_2DUP
	db SF_PLUS
	d2 TOS
	db SF_EXIT

DOTQUO:	db H_RSR
SDOTQUO: db H_COL
	d2 SSTRGOBBLE
        d2 TYPE
        db SF_EXIT

DDQUO:	db H_RSR
SDDQUO:	db H_COL
	d2 SDOTQUO
	d2 CR
	d2 SDOTQUO
	db SF_EXIT

DEMO:	db H_COL
	d2 DDQUO
	db 5, 'Hello'
	db 5, 'There'
	db SF_EXIT
---
nasm -f bin -o /tmp/demo /tmp/demo.asm
nasm -f elf -o /tmp/demoelf /tmp/demo.asm
objdump -xasf /tmp/demoelf

#*

# (find-enode "Editing Binary Files")
# (hexl-find-file "/tmp/demo")

# 0000: fbfcfd 3412
# 0005: ff fa03 fa00 fd fe fa04 ff
# 000f: feff 0005 fa01 ff
# 0016: feff 0010 fa02 0010 ff
# 001f: ff 0016 0548656c6c6f 055468657265 ff





#####
#
# regexps in C
# 2000jun18
#
#####

# (find-node "(libc)POSIX Regexp Compilation")
# (find-node "(libc)Matching POSIX Regexps")
# (eeman "3 regcomp")

# int regcomp(regex_t *preg, const char *regex, int cflags);
# int regexec(const regex_t *preg, const char *string,
#	      size_t nmatch, regmatch_t pmatch[], int eflags);

#*
cat > /tmp/ctmp.c <<'---'
#include <stdio.h>
#include <regex.h>
int main(int argc, char **argv) {
  regex_t r;
  regmatch_t pmatch[10];
  printf("%d\n", regcomp(&r, argv[1], 0));
  printf("%d\n", regexec(&r, argv[2], 10, pmatch, 0));
  return 0;
}
---
gcc -E /tmp/ctmp.c > /tmp/ctmp.E
gcc -Wall -o /tmp/ctmp /tmp/ctmp.c \
  && /tmp/ctmp ab cabbab

#*

# (find-es "debian0" "boot-floppies-src")
# (find-bffile "utilities/busybox/regexp.c")
# (find-bffile "utilities/busybox/regexp.h")





#####
#
# Using gdb to inspect C types
# 2000oct14
#
#####

# «gdb_and_C_types»  (to ".gdb_and_C_types")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)

# (find-fline "/tmp/c/")
rm -Rv /tmp/c/
mkdir  /tmp/c/
cd     /tmp/c/

cat > m.c <<'%%%'
#include <stdio.h>
#include <stdlib.h>
double (*m)[10];

int main() {
  int i, j, n;
  m = malloc(8*20*10);
  for(i=0, n=0; i<20; ++i)
    for(j=0; j<10; ++j, ++n)
      m[i][j] = n;

  for(i=0, n=0; i<20; ++i)
    for(j=0; j<10; ++j, ++n)
      printf("%f ", m[i][j]);
}
%%%
gcc -g -o m m.c
./m

gdb ./m
  br main
  run
  ptype m
  ptype *m
  ptype **m
  cont
  quit

# (find-node "(gdb)Continuing and Stepping")
# (find-node "(gdb)Quitting GDB")



# Now you may either invoke gdb directly with, say,
gdb /tmp/m < $EEG
# or from Emacs, using my .gdbinit and gdbk-mode, with:
# (progn (gdb "gdb /tmp/m") (gdbk-mode))
# For more info:
#   (find-angg ".gdbinit")
#   (find-angg ".emacs" "gdbk-mode")





#####
#
# cdecl
# 2000dec18 / 2011sep15
#
#####

# «cdecl»  (to ".cdecl")
# (find-angg ".emacs" "find-cdecl")
# (find-sh "apt-file search cdecl")
# (find-zsh "dmissing cdecl")
# (find-es "debian" "diversions")
# (find-status   "cdecl")
# (find-vldifile "cdecl.list")
# (find-udfile   "cdecl/")
# (find-status   "cutils")
# (find-vldifile "cutils.list")
# (find-udfile   "cutils/")
# (find-node "(cutils)Top")
# (find-node "(cutils)cdecl/cundecl examples")
# (find-man "1 cdecl")
# (find-man "1 cdecl" "\nGRAMMAR")
# (find-man "1 cdecl.cutils")
# (find-es "swig" "C-types-as-strings")

# (find-man "1 cdecl" "SYNONYMS")
# (find-man "1 cdecl" "EXAMPLES")

apti cdecl cutils

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cdecl help
cdecl
  help
  declare fptab as array of pointer to function returning pointer to char
  declare fptab as array of ptr to func ret ptr to char
  explain char *(*fptab[])()

  declare f as pointer to function returning int
  explain int (*f)()
  explain int (*f)(int, int)
  declare f as pointer to function (int, int) returning int

  exit

* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
cdecl.cutils <<'%%%'
char *s;
void (*signal(int sig, void (*func)(int)))(int);
(const char *)s;
(void (*)(int))signal_function;
const char *const *argv;
%%%

cundecl <<'---'
declare s as pointer to char;
declare x as function (fmt as pointer to const char, ...) returning int;
cast s into pointer to const char;
cast f into pointer to function (int) returning void;
---




#####
#
# pointer-to-function
# 2021sep19
#
#####

# «pointer-to-function»  (to ".pointer-to-function")
# (find-angg "C/pointer-to-function.c")
# (find-books "__comp/__comp.el" "kernighan-ritchie")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cdecl
  declare f as pointer to function returning int
  explain int (*f)()
  explain int (*f)(int, int)
  declare f as pointer to function (int, int) returning int
  exit




#####
#
# A zsh function to execute a string as C code
# 2000dec18
#
#####

# «c_eval»  (to ".c_eval")
#*
function ccc () {
  echo "#include <stdio.h>\nmain(int argc, char **argv){ $1 }" > /tmp/ccc.c
  gcc -o /tmp/ccc /tmp/ccc.c && /tmp/ccc $*[2,-1]
  rm /tmp/ccc{,.c}
}

ccc 'int cc, c=0, l=0; while( (cc=fgetc(stdin)) != EOF ) {
  c++; l+=(cc==10)?1:0; } printf("character: %d\nlines: %d\n",c,l);
' < /etc/passwd
#*




#####
#
# dlopen (with thx to ctrl-alt-dels)
# 2000dec22
#
#####

# «dlopen»  (to ".dlopen")
# (find-man "3 dlopen")
# (find-man "3 dlopen" "EXAMPLE")

#*
cd /tmp/
cat > so.c <<'---'
#include <stdio.h>
void distant() {
  printf("Hello from a distant place.\n");
}
---
                    gcc -g -Wall -shared -o so.so so.c
# i386-uclibc-linux-gcc -g -Wall -shared -o so.so so.c

cat > x.c <<'---'
#include <dlfcn.h>
#include <stdio.h>
int main() {
  void *libptr;
  void (*f)();
  printf("After an effort of concentration you hear a\n");
  libptr=dlopen("/tmp/so.so", RTLD_LAZY);
  f=dlsym(libptr, "distant");
  /* printf("%x %x\n", libptr, f); */
  f();
  printf("Bye now.\n");
  return 0;
}
---
                    gcc -g -Wall -ldl -o x x.c
# i386-uclibc-linux-gcc -g -Wall -ldl -o x x.c
./x

#*
# «dlopen-gdb»  (to ".dlopen-gdb")
# gdb will happily enter into dynamically loaded modules...
# Run the `eegud-gdb' hyperlink here and single-step with M-s or M-n.
# (find-eev "e/tutorial.e" "eegud")
br main
run

# (ee-once (eeb-gdb-start "/tmp/" "x"))
#*






#####
#
# understanding how gcc builds an executable (with gcc -v)
# 2001jan18
#
#####

# «gcc-v»  (to ".gcc-v")
#*
cd /tmp/
cat > x.c <<'---'
#include <stdio.h>
int main() {
  printf("Hello!\n");
  return 0;
}
---
gcc -v -o x x.c |& tee /tmp/o
# (find-fline "/tmp/o")

#*
# After some cleaning...
# (find-node "(gcc)Option Summary")
# (find-node "(gcc)Overall Options")

cd /tmp/
/usr/lib/gcc-lib/i386-linux/2.95.2/cpp -lang-c				\
  -D__GNUC__=2 -D__GNUC_MINOR__=95 -D__ELF__ -Dunix -D__i386__ -Dlinux	\
  -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux	\
  -A"system(posix)"							\
  -Wall -A"cpu(i386)" -A"machine(i386)"					\
  -Di386 -D__i386 -D__i386__ x.c x.i

/usr/lib/gcc-lib/i386-linux/2.95.2/cc1 x.i		\
  -quiet -dumpbase x.c -Wall -version -o x.s

as -V -Qy -o x.o x.s

cat > /tmp/ld <<'---'
#!/bin/sh
echo
echo ld $*
exec /usr/bin/ld $*
---
chmod 755 /tmp/ld

# (find-angg ".zshrc" "strace")
PATH=/tmp:$PATH \
vfwstrace -f -q -e trace=file -o ~/s \
/usr/lib/gcc-lib/i386-linux/2.95.2/collect2 -m elf_i386		\
  -dynamic-linker /lib/ld-linux.so.2				\
  -o x								\
  /usr/lib/crt1.o /usr/lib/crti.o				\
  /usr/lib/gcc-lib/i386-linux/2.95.2/crtbegin.o			\
  -L/usr/lib/gcc-lib/i386-linux/2.95.2				\
  x.o								\
  -lgcc -lc -lgcc						\
  /usr/lib/gcc-lib/i386-linux/2.95.2/crtend.o /usr/lib/crtn.o

rm -v /tmp/ld
#*

# sort ~/s | l
# (find-fline "~/s")
grep open ~/s | grep -v ENOENT | getstrings | sort | uniq | tee ~/o
# (find-fline "~/o")

#*

#I am quite sure that the resulting "x" was built from these files...
# /usr/lib/crt1.o
# /usr/lib/crti.o
# /usr/lib/crtn.o
# /usr/lib/gcc-lib/i386-linux/2.95.2/crtbegin.o
# /usr/lib/gcc-lib/i386-linux/2.95.2/crtend.o
# /tmp/x.o

#Not so sure about these ones...
# /lib/ld-linux.so.2
# /lib/libc.so.6
# /usr/lib/gcc-lib/i386-linux/2.95.2/libgcc.a
# /usr/lib/libc.so

#And I don't have a clue if these ones are are used:
# /usr/lib/libbfd-2.9.5.0.37.so
# /usr/lib/libc_nonshared.a
# /lib/libdl.so.2


#Packages owning those files:
# binutils:  /usr/lib/libbfd-2.9.5.0.37.so
# gcc:       /usr/lib/gcc-lib/i386-linux/2.95.2/crtbegin.o
# gcc:       /usr/lib/gcc-lib/i386-linux/2.95.2/crtend.o
# gcc:       /usr/lib/gcc-lib/i386-linux/2.95.2/libgcc.a
# libc6:     /lib/ld-linux.so.2
# libc6:     /lib/libc.so.6
# libc6:     /lib/libdl.so.2
# libc6-dev: /usr/lib/crt1.o
# libc6-dev: /usr/lib/crti.o
# libc6-dev: /usr/lib/crtn.o
# libc6-dev: /usr/lib/libc.so
# libc6-dev: /usr/lib/libc_nonshared.a

# (find-gccfile "odrb" "crtbegin.o")
# (find-gccfile "odrb" "crtend.o")






#####
#
# libvforkwrap, as Linux doesn't strace over vforks
# 2000jan19 / 2019sep25
#
#####

# «libvforkwrap»  (to ".libvforkwrap")
# (find-angg ".zshrc" "strace")
# (find-deblistsw3 "debian-mentors-0007/msg00089.html")
# https://lists.debian.org/debian-mentors/
# https://lists.debian.org/debian-mentors/2000/07/threads.html
# https://lists.debian.org/debian-mentors/2000/07/msg00089.html
# https://lists.debian.org/debian-mentors/2000/07/bing9kQTwyJYb.bin
# https://lists.debian.org/debian-mentors/2000/07/libvforkwrap-0.1.tar.gz
# https://lists.debian.org/debian-mentors/2000/07/

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd $S/https/lists.debian.org/debian-mentors/2000/07/
mv bing9kQTwyJYb.bin libvforkwrap-0.1.tar.gz

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# (find-fline "~/usrc/libvforkwrap-0.1/")
rm -Rv ~/usrc/libvforkwrap-0.1/
mkdir  ~/usrc/libvforkwrap-0.1/
tar -C ~/usrc/ -xvzf $S/https/lists.debian.org/debian-mentors/2000/07/libvforkwrap-0.1.tar.gz
cd     ~/usrc/libvforkwrap-0.1/

make  |& tee om

# (code-c-d "libvforkwrap" "~/usrc/libvforkwrap-0.1/")
# (find-libvforkwrapfile "")

#*
# «LD_PRELOAD»  (to ".LD_PRELOAD")
# (find-libvfwfile "")
# (find-libvfwfile "dpkg-genbuilddeps" "LD_PRELOAD")
# (find-man "8 ld.so" "LD_PRELOAD")
# (find-man "1 strace" "-e trace=file")

# Sample usage (these examples use fake files!):

LD_PRELOAD="/usr/src/libvforkwrap-0.1/libvforkwrap.so.0 $LD_PRELOAD" \
  strace -q -f -e trace=file -o ~/s \
    program_that_used_to_call_vfork args

# (find-angg ".zshrc" "strace")
vfwstrace -q -f -e trace=file -o ~/s \
  program_that_used_to_call_vfork args




# (find-man "1 ld")
# (find-man "1 ld" "--wrap=symbol")
# See a message by Robert Jakabosky in lua-l, 2011mar08






#####
#
# gcc source
# 2000dec23
#
#####

# «gcc_source»  (to ".gcc_source")
#*
pdsc $SDEBIAN/dists/potato/main/source/devel/gcc_2.95.2-13.dsc
cd /usr/src/gcc-2.95.2/
debian/rules unpack	|& tee odru
cd /usr/src/gcc-2.95.2/src/
find .* * | sort > .files

#*
# Making just crtbegin.o, crtend.o, and libgcc.a:
cd /usr/src/gcc-2.95.2/
debian/rules configure		|& tee odrc
cd /usr/src/gcc-2.95.2/build/libiberty/
make libiberty.a		|& tee om
cd /usr/src/gcc-2.95.2/build/gcc/
make crtbegin.o crtend.o	|& tee omcrt
make libgcc.a			|& tee omlibgcc
# (find-gccfile "build/gcc/")
# (find-gccfile "build/gcc/Makefile" "crtbegin.o:")
# (find-gccfile "build/gcc/Makefile" "libgcc.a:")
# (find-gccfile "build/gcc/omcrt")
# (find-gccfile "build/gcc/omlibgcc")

#*
cd /usr/src/gcc-2.95.2/
(time debian/rules binary)	|& tee odrb
# 30 mins and it broke with an error at src/libio/filebuf.cc...

#*
# (code-c-d "gcc" "/usr/src/gcc-2.95.2/")
# (code-c-d "gcc0" "/usr/src/gcc0-2.95.2/")
# (find-gccfile "src/gcc/crtstuff.c")
# (find-gccfile "src/gcc/config/i386/crtdll.h")
# (find-gccfile "src/gcc/config/i386/t-crtpic")
# (find-gccfile "src/gcc/config/i386/t-crtstuff")
# (find-gccfile "debian/")
# (find-gccfile "src/")
# (find-gccfile "src/.files")
# (find-gccfile "odrb")
# (find-gccfile "odrb" "crtbegin.o" )
# (find-gccfile "odrb" "libgcc.a" )





#####
#
# glibc (libc6) source
#
#####

# «glibc-src»  (to ".glibc-src")
# (find-glibcfile "debian/control")
apti kernel-headers-2.2.15

#*
pdsc $SDEBIAN/dists/potato/main/source/libs/glibc_2.1.3-10.dsc
cd /usr/src/glibc-2.1.3/

# (find-glibcfile "debian/")
# (find-glibcfile "debian/README")

# debian/rules unpack		|& tee odru
debian/rules configure		|& tee odrc

cd /usr/src/glibc-2.1.3/glibc-2.1.3/
find * -type f | sort > .files
# glimpseindex -H . -F < .files

cd /usr/src/glibc-2.1.3/
# debian/rules binary		|& tee odrb
# make -C /usr/src/glibc-2.1.3/i386-linux/obj PARALLELMFLAGS=""	|& tee om
# (cd /usr/src/glibc-2.1.3/i386-linux/obj/; make)		|& tee om

cd /usr/src/glibc-2.1.3/glibc-2.1.3/
make -r objdir=/usr/src/glibc-2.1.3/i386-linux/obj all		|& tee om
# (find-glibcsfile "om")

# (find-glibcofile "")
# (find-glibcofile "Makefile")
# (find-glibcfile "debian/rules")
# (find-glibcfile "debian/rules" "arch_packages")
# (find-glibcfile "debian/sysdeps/")
# (find-glibcfile "debian/sysdeps/sysdeps.mk")
#*

glibcglimpse crt1
#*

# Files that I'm trying to learn how to make:
# libc6:     /lib/ld-linux.so.2
# libc6:     /lib/libc.so.6
# libc6:     /lib/libdl.so.2
# libc6-dev: /usr/lib/crt1.o
# libc6-dev: /usr/lib/crti.o
# libc6-dev: /usr/lib/crtn.o
# libc6-dev: /usr/lib/libc.so
# libc6-dev: /usr/lib/libc_nonshared.a

# (code-c-d "glibc" "/usr/src/glibc-2.1.3/")
# (code-c-d "glibcs" "/usr/src/glibc-2.1.3/glibc-2.1.3/")
# (code-c-d "glibco" "/usr/src/glibc-2.1.3/i386-linux/obj/")
# (code-c-d "glibcd" "/usr/src/glibc-2.1.3/debian/")
# (find-glibcfile "")
# (find-glibcfile "log-build-i386-linux")
# (find-glibcfile "debian/")
# (find-glibcfile "debian/control")
# (find-glibcsfile "FAQ")
# (find-glibcsfile "csu/")
# (find-glibcsfile "csu/Makefile")
# (find-glibcsfile "csu/Makefile" "C startup code")
# (find-glibcofile "")




#####
#
# ld.so
# 2000jan19
#
#####

# «ld.so»  (to ".ld.so")
#*
pdsc $SDEBIAN/dists/potato/main/source/base/ld.so_1.9.11-9.dsc
cd /usr/src/ld.so-1.9.11/
find * | sort > .files

#*
# (find-ldsofile "")
# (find-ldsofile "test/")




#####
#
# Regexps
# 2001nov14
#
#####

# «regexps»  (to ".regexps")
# (find-node "(libc)Regular Expressions")
# (find-node "(libc)POSIX Regexp Compilation")
# (find-node "(libc)POSIX Regexp Compilation" "Function: int regcomp")
# (find-man "7 regex")
# (find-man "7 regex" "Henry Spencer's")
# (find-man "3 regcomp")

# (find-fline "/usr/include/regex.h")
# (find-fline "/usr/include/regexp.h")
# (find-fline "/usr/include/regex.h" "#define RE_SYNTAX_EMACS 0")
# (find-fline "/usr/include/regex.h" "extern int re_match")

# (find-angg "lua-4.0/src/libdllua/lrexlib-new.c")
# (find-angg "lua-4.0/src/libdllua/lrexlib.c")
# (find-fline "~/lua-4.0/src/libdllua/lrexlib.c" "res = regcomp")

  res = regcomp(rp, pattern, REG_EXTENDED | REG_PEND);

# (find-man "3 regcomp")
# (find-man "3 regcomp" "regcomp returns zero")
# (find-es "emacs" "faces")
# (set-text-properties (point) (mark) nil)
# (find-node "(libc)Parsing of Integers")

#*
rm -Rv /tmp/regex/
mkdir  /tmp/regex/
cd     /tmp/regex/

cat > regtest.c <<'---'
#include <stdlib.h>
#include <stdio.h>
#include <regex.h>

int main(int argc, const char **argv) {
  regex_t *preg;
  char *regex, *string, errbuf[80];
  int errcode, r, cflags, nmatch, eflags;
  regmatch_t pmatch[10];
  preg = malloc(sizeof(regex_t));

  cflags = atoi(argv[1]);
  eflags = atoi(argv[2]);
  regex  = argv[3];
  string = argv[4];

  errcode = regcomp(preg, regex, cflags);
  if (errcode) {
    r = regerror(errcode, preg, errbuf, sizeof(errbuf));
    printf("%s\n", errbuf);
    exit(1);
  }
  nmatch = preg->re_nsub;
  r = regexec(preg, string, nmatch, pmatch, eflags);
  if (r)
    exit(2);
  printf("found!\n");
  return 0;
}
---
gcc -Wall -g -o regtest regtest.c

cd /tmp/regex/
./regtest 0 0 foo banafooba

#*
# (gdbk-gdb 'do-eeg-bounded "/tmp/regex/regtest")
set args 0 0 'f(o)o' banafooba
br main
run

#*




#####
#
# system
# 2002feb08
#
#####

# «system»  (to ".system")
# (find-node "(libc)Running a Command")
# (find-node "(libc)Program Arguments")
# (find-fline "~/tmp/lua-4.0/src/lua/lua.c" "int main")
#*
cd ~/tmp/
cat > test.c <<'---'
#include "stdlib.h"
int main(int argc, char *argv[]) {
  system("cd /tmp; ls");
}
---
gcc -o test test.c
./test

#*
# «edrxroot»  (to ".edrxroot")
# (find-node "(libc)Process Persona")
# (find-node "(sh-utils)whoami invocation")
# (find-node "(sh-utils)id invocation")

# (find-man "2 chmod")
# I want to copy edrxroot to /edrx and to chmod it to 4755:
chmod -v --reference=/bin/ping /bin/ping

cd ~/tmp/
cat > edrxroot.c <<'---'
#include "stdlib.h"
int main(int argc, char *argv[]) {
  system("test $(id -rnu) = ochs && cd /home/ochs/edrx && exec ./run-zsh");
}
---
gcc -o edrxroot edrxroot.c
cp -v edrxroot /tmp/
./edrxroot

#*




#####
#
# biew
# 2003jul01
#
#####

# «biew»  (to ".biew")
# (find-available "biew")
# (find-status   "biew")
# (find-vldifile "biew.list")
# (find-udfile   "biew/")



#####
#
# steps in a "for" loop
# 2001jul26
#
#####

#*
cat > /tmp/for.c <<'---'
#include <stdio.h>
#define P printf
main() {
  int i;
  for (P("for_init"),i=0; P(" test\n"),i<4; P(" incr"),++i) {
    P(" code");
  }
  return 0;
}
---
gcc -o /tmp/for /tmp/for.c
/tmp/for

#*





#####
#
# Linker scripts
# 2001mar01
#
#####

# (find-node "(ld)Simple Example")
# (find-fline "/usr/lib/ldscripts/")

# (find-status "binutils")
# (find-vldifile "binutils.list")
# (find-fline "/usr/doc/binutils/")




#####
#
# dietlibc
# 2004oct10 / 2019sep19
#
#####

# «dietlibc»  (to ".dietlibc")
# https://en.wikipedia.org/wiki/Dietlibc
# http://www.fefe.de/dietlibc/
# https://packages.debian.org/source/sid/dietlibc
# (find-zsh "installeddebs | sort | grep dietlibc")
# (find-zsh "availabledebs | sort | grep dietlibc")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
apti dietlibc-dev dietlibc-doc

apti dietlibc dietlibc-dev dietlibc-doc
# http://www.fefe.de/dietlibc/
# (find-status   "dietlibc-doc")
# (find-vldifile "dietlibc-doc.list")
# (find-udfile   "dietlibc-doc/")
# (find-status   "dietlibc-dev")
# (find-vldifile "dietlibc-dev:amd64.list")
# (find-udfile   "dietlibc-dev/")
# (find-status   "dietlibc")
# (find-vldifile "dietlibc.list")
# (find-udfile   "dietlibc/")
# (find-man "1 diet")
#*
rm -Rv ~/usrc/dietlibc/
mkdir  ~/usrc/dietlibc/
cd     ~/usrc/dietlibc/
#*
rm -Rv ~/usrc/dietlibc/dietlibc-0.27/
mkdir  ~/usrc/dietlibc/
cd     ~/usrc/dietlibc/
apt-get source dietlibc
#*
# (code-c-d "dietlibc" "~/usrc/dietlibc/dietlibc-0.27/")
# (find-dietlibcfile "")
# (find-dietlibcfile "lib/")
# (find-dietlibcfile "lib/__v_printf.c")
# (find-dietlibcfile "libstdio/")
# (find-dietlibcfile "test/")

# How to use "diet"
# (find-lua51file "Makefile")




#####
#
# dietlibc-git
# 2019sep20
#
#####

# «dietlibc-git» (to ".dietlibc-git")
# https://salsa.debian.org/debian/dietlibc.git
# (find-git-links "https://salsa.debian.org/debian/dietlibc.git" "dietlibc")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# rm -Rfv ~/usrc/dietlibc/
cd      ~/usrc/
git clone https://salsa.debian.org/debian/dietlibc.git
cd      ~/usrc/dietlibc/

git branch --list -a
git for-each-ref
PAGER=cat git log --oneline --graph --all -20

# (find-fline "~/usrc/")
# (find-fline "~/usrc/dietlibc/")
# (find-gitk  "~/usrc/dietlibc/")

# (code-c-d "dietlibc" "~/usrc/dietlibc/")
# (find-dietlibcfile "")




#####
#
# dietlibc (from the debian sources)
# 2013jan31
#
#####

# «dietlibc-deb-src» (to ".dietlibc-deb-src")
# (find-apt-get-source-links "dietlibc")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# (find-sh "apt-cache show    dietlibc")
# (find-sh "apt-cache showsrc dietlibc")
rm -Rv /tmp/d/
mkdir  /tmp/d/
cd     /tmp/d/
sudo apt-get build-dep -y   dietlibc
     apt-get source         dietlibc   2>&1 | tee osource
     apt-get source --build dietlibc   2>&1 | tee osourceb

# (find-fline "/tmp/d/")
# (find-fline "/tmp/d/osourceb" "is maintained in the 'Git' version")

;; (find-code-pdf-links "/tmp/d/dietlibc-0.34~cvs20160606/.cvsignore" "dietlibc")
;; (find-fline "/tmp/d/dietlibc-0.34~cvs20160606/")
(code-c-d "dietlibc" "/tmp/d/dietlibc-0.34~cvs20160606/")
# (find-dietlibcfile "")
# (find-dietlibcfile "examples/")
# (find-dietlibcfile "examples/Makefile")
# (find-dietlibcfile "examples/sln.c")

cd /tmp/d/dietlibc-0.34~cvs20160606/examples/
make clean
make sln



# Old:
# http://ftp.de.debian.org/debian/pool/main/d/dietlibc/
# http://ftp.de.debian.org/debian/pool/main/d/dietlibc/dietlibc_0.32-5.1.dsc
# http://ftp.de.debian.org/debian/pool/main/d/dietlibc/dietlibc_0.32-5.1.diff.gz
# http://ftp.de.debian.org/debian/pool/main/d/dietlibc/dietlibc_0.32.orig.tar.gz
#*
rm -Rv ~/usrc/dietlibc/
mkdir  ~/usrc/dietlibc/
cd $S/http/ftp.de.debian.org/debian/pool/main/d/dietlibc/
cp -v dietlibc_0.32* ~/usrc/dietlibc/
cd     ~/usrc/dietlibc/
dpkg-source -sn -x dietlibc_0.32-5.1.dsc
cd     ~/usrc/dietlibc/dietlibc-0.32/
dpkg-buildpackage -us -uc -b -rfakeroot     |& tee odb

#*
# (find-fline "~/usrc/dietlibc/")
* (eepitch-shell)
cd ~/usrc/dietlibc/
sudo dpkg -i *.deb

#*
# (code-c-d "dietlibc" "~/usrc/dietlibc/dietlibc-0.32/")
# (find-dietlibcfile "")







#####
#
# uclibc
# 2005mar05 / 2019sep19
#
#####

# «uclibc»  (to ".uclibc")
# https://en.wikipedia.org/wiki/UClibc
# https://www.uclibc.org/
# (find-zsh "installeddebs | sort | grep uclibc")
# (find-zsh "availabledebs | sort | grep uclibc")
# (find-status   "libuclibc-dev")
# (find-vldifile "libuclibc-dev.list")
# (find-udfile   "libuclibc-dev/")
# (find-status   "uclibc-toolchain")
# (find-vldifile "uclibc-toolchain.list")
# (find-udfile   "uclibc-toolchain/")
# (find-status   "libuclibc0")
# (find-vldifile "libuclibc0.list")
# (find-udfile   "libuclibc0/")

# http://ftp.debian.org/debian/pool/main/u/uclibc/
#*
rm -Rv ~/bigsrc/uclibc/
mkdir  ~/bigsrc/uclibc/
cd     ~/bigsrc/uclibc/
dpkg-source -x $S/http/ftp.debian.org/debian/pool/main/u/uclibc/uclibc_0.9.26-cvs20040816-5.1.dsc

~/bigsrc/uclibc/uclibc-0.9.26-cvs20040816/
find * -type f -name '*.[chS]' | sort > .files.chS

#*
# (code-c-d "uclibc" "~/bigsrc/uclibc/uclibc-0.9.26-cvs20040816/")
# (find-uclibcfile "")
# (find-uclibcfile "libc/stdlib/")
# (find-uclibcfile "libc/stdio/")
# (find-uclibcfile "libc/stdio/vfprintf.c")





#####
#
# uclibc from the upstream sources
# 2005nov10
#
#####

# «uclibc-upstream»  (to ".uclibc-upstream")
# http://www.uclibc.org/
# http://www.uclibc.org/downloads/
# http://www.uclibc.org/downloads/uClibc-0.9.29.tar.bz2
#*
rm -Rv ~/bigsrc/uClibc-0.9.29/
mkdir  ~/bigsrc/uClibc-0.9.29/
cd     ~/bigsrc/uClibc-0.9.29/
tar -C ~/bigsrc/ -xvjf \
  $S/http/www.uclibc.org/downloads/uClibc-0.9.29.tar.bz2

find * -type d | sort > .dirs
find * -type f -name '*.[chS]' | sort > .files.chS

# (find-uclibcsh "cd libpthread/linuxthreads/sysdeps/; ls | paste -s -d'|'")
egrep -v '/(alpha|arm|bfin|cris|frv|m68k|mips|nios|nios2|powerpc|pthread|sh|sh64|sparc|v850|x86_64)/' < .files.chS > .files.chS-
egrep -v '/(e1|h8300|i960|microblaze)/' < .files.chS- > .files.chS--

etags $(cat .files.chS--)

#*
# (code-c-d "uclibc" "~/bigsrc/uClibc-0.9.29/")
# (find-uclibcfile "")
# (find-uclibctag "strncmp")





#####
#
# uclibc (from the debian sources)
# 2013jan31
#
#####

# «uclibc-deb-src» (to ".uclibc-deb-src")
# (find-zsh "availabledebs | sort | grep uclibc")
# http://ftp.de.debian.org/debian/pool/main/u/uclibc/
# http://ftp.de.debian.org/debian/pool/main/u/uclibc/uclibc_0.9.30.2-1.dsc
# http://ftp.de.debian.org/debian/pool/main/u/uclibc/uclibc_0.9.30.2-1.debian.tar.gz
# http://ftp.de.debian.org/debian/pool/main/u/uclibc/uclibc_0.9.30.2.orig.tar.bz2
#*
rm -Rv ~/usrc/uclibc/
mkdir  ~/usrc/uclibc/
cd $S/http/ftp.de.debian.org/debian/pool/main/u/uclibc/
cp -v uclibc_0.9.30.2* ~/usrc/uclibc/
cd     ~/usrc/uclibc/
dpkg-source -sn -x uclibc_0.9.30.2-1.dsc
cd     ~/usrc/uclibc/uclibc-0.9.30.2/
dpkg-buildpackage -us -uc -b -rfakeroot     |& tee odb

#*
# (find-fline "~/usrc/uclibc/")
* (eepitch-shell)
cd ~/usrc/uclibc/
sudo dpkg -i *.deb

#*
# (code-c-d "uclibc" "~/usrc/uclibc/uclibc-0.9.30.2/")
# (find-uclibcfile "")
# (find-uclibcfile "docs/Glibc_vs_uClibc_Differences.txt")







#####
#
# newlib (from the debian sources)
# 2008sep02
#
#####

# «newlib-deb-src»  (to ".newlib-deb-src")
# http://ftp.debian.org/debian/pool/main/n/newlib/
# http://ftp.debian.org/debian/pool/main/n/newlib/newlib_1.16.0-3.dsc
# http://ftp.debian.org/debian/pool/main/n/newlib/newlib_1.16.0-3.diff.gz
# http://ftp.debian.org/debian/pool/main/n/newlib/newlib_1.16.0.orig.tar.gz
#*
sudo apt-get build-dep newlib
#*
rm -Rv ~/bigsrc/newlib/
mkdir  ~/bigsrc/newlib/
cd $S/http/ftp.debian.org/debian/pool/main/n/newlib/
cp -v newlib_1.16.0* ~/bigsrc/newlib/
cd     ~/bigsrc/newlib/
dpkg-source -sn -x newlib_1.16.0-3.dsc
cd     ~/bigsrc/newlib/newlib-1.16.0/
dpkg-buildpackage -us -uc -b -rfakeroot     |& tee odb

#*
# (find-fline "~/bigsrc/newlib/")
* (eepitch-shell)
cd ~/bigsrc/newlib/
sudo dpkg -i *.deb

#*
# (code-c-d "newlib" "~/bigsrc/newlib/newlib-1.16.0/")
# (find-newlibfile "")




#####
#
# newlib - upstream version
# 2008sep02
#
#####

# «newlib-upstream»  (to ".newlib-upstream")
# (find-es "lua5" "elua")
# (find-es "emacs" "emacs-from-cvs")
# ftp://sources.redhat.com/pub/newlib/index.html
# http://sources.redhat.com/newlib/download.html
#*
rm -Rv ~/bigsrc/newlib/
mkdir  ~/bigsrc/newlib/
cd     ~/bigsrc/newlib/
tar -xvzf ~/tmp/newlib-cvs.tgz
cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src login
# {enter "anoncvs" as the password}
cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/src co newlib   |& tee oc
tar -cvzf ~/tmp/newlib-cvs.tgz src/

#*
rm -Rv ~/bigsrc/newlib/
mkdir  ~/bigsrc/newlib/
cd     ~/bigsrc/newlib/
tar -xvzf ~/tmp/newlib-cvs.tgz
cd     ~/bigsrc/newlib/src/

CC=gcc ./configure   |& tee oc
make                 |& tee om
make all-hello       |& tee omah

#*
# (code-c-d "newlib" "~/bigsrc/newlib/src/")
# (find-newlibfile "")
# (find-newlibfile "Makefile")
# (find-newlibfile "Makefile" "info: do-info")
# (find-newlibfile "Makefile" "\ndist:\n")
# (find-newlibfile "Makefile" "\nall-build-bison:")
# (find-newlibfile "README")
# (find-newlibsh "CC=gcc ./configure --help")

# http://elua.berlios.de/tut_gcc_arm.html
# http://www.gnu.org/software/binutils/
# http://www.gnu.org/software/gcc/
# http://www.gnu.org/software/gcc/gcc-4.3/
# ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.3.2/
# ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.3.2/gcc-4.3.2.tar.bz2

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
sudo apt-get install flex bison libgmp3-dev libmpfr-dev autoconf texinfo


Next, decide where you want to install your toolchain. They generally go in /usr/local/, so I'm going to assume /usr/local/cross-arm for this tutorial. To save
yourself some typing, set this path into a shell variable:

# export TOOLPATH=/usr/local/cross-arm
export TOOLPATH=/tmp/local-cross-arm
mkdir $TOOLPATH/

: Step 1: binutils

This is the easiest step: unpack, configure, build.

 $ tar xvfj binutils-2.17.tar.bz2
 $ cd binutils-2.17
 $ mkdir build
 $ cd build
 $ ../configure --target=arm-elf --prefix=$TOOLPATH --enable-interwork --enable-multilib 
   --with-gnu-as --with-gnu-ld --disable-nls
 $ make all
 $ sudo make install
 $ export PATH=${TOOLPATH}/bin:$PATH



#####
#
# binutils upstream
# 2008sep06
#
#####

# http://ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2
#*
rm -Rv ~/bigsrc/binutils-2.18/
tar -C ~/bigsrc/ -xvjf \
  $S/http/ftp.gnu.org/gnu/binutils/binutils-2.18.tar.bz2
cd     ~/bigsrc/binutils-2.18/

export TOOLPATH=/tmp/local-cross-arm
mkdir $TOOLPATH/

cd ~/bigsrc/binutils-2.18/
mkdir build/
cd    build/
../configure \
   --target=arm-elf --prefix=$TOOLPATH --enable-interwork \
   --enable-multilib --with-gnu-as --with-gnu-ld --disable-nls \
     |& tee oc

make all   |& tee oma
# sudo make install
# export PATH=${TOOLPATH}/bin:$PATH

#*
export TOOLPATH=/tmp/local-cross-arm
mkdir $TOOLPATH/



# (code-c-d "binutils" "~/bigsrc/binutils-2.18/")
# (find-binutilsfile "")
# (find-binutilsfile "build/")
# (find-binutilsfile "build/oc")
# (find-binutilsfile "build/oma")
# (find-binutilsfile "build/oma" "checking for makeinfo")
# (find-binutilsfile "configure" "For an installed makeinfo")
# (find-binutilsfile "build/config.log")
# (find-binutilsfile "build/config.log" "checking for makeinfo")
# (find-binutilsfile "build/config.log" "MAKEINFO=")
# (find-binutilsfile "build/config.log" "\nMAKEINFO=")
# (find-binutilsfile "build/config.status")
# (find-binutilsfile "build/config.status" "s,@MAKEINFO@,")

# (find-status   "texinfo")
# (find-vldifile "texinfo.list")
# (find-udfile   "texinfo/")






#####
#
# tcc
# 2006jul07 / 2019sep21
#
#####

# «tcc»  (to ".tcc")
# (find-zsh "installeddebs | sort | grep tcc")
# (find-zsh "availabledebs | sort | grep tcc")
# (find-status   "tcc")
# (find-vldifile "tcc.list")
# (find-udfile   "tcc/")
# (find-node "(tcc-doc)Top")
# (find-udfile "tcc/examples/")
# (find-udfile "tcc/examples/ex1.c")
# (find-udfile "tcc/examples/ex2.c")
# (find-udfile "tcc/examples/ex3.c")
# (find-udfile "tcc/examples/ex4.c")
# (find-udfile "tcc/examples/ex5.c")
# (find-man "1 tcc")
# /usr/share/doc/tcc/tcc-doc.html

# «endianness»  (to ".endianness")
# On an x86 the programs below print '78'.

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd /tmp/
cat > foo.c <<'%%%'
int main () {
  int a = 0x12345678;
  printf("%x\n", *(char *)(&a));
}
%%%
tcc -run foo.c

tcc -run - <<'%%%'
int main () {
  int a = 0x12345678;
  printf("%x\n", *(char *)(&a));
}
%%%




#####
#
# tcc (from the debian sources)
# 2007dec20
#
#####

# «tcc-deb-src»  (to ".tcc-deb-src")
# http://ftp.debian.org/debian/pool/main/t/tcc/
# http://ftp.debian.org/debian/pool/main/t/tcc/tcc_0.9.23-4.dsc
# http://ftp.debian.org/debian/pool/main/t/tcc/tcc_0.9.23-4.diff.gz
# http://ftp.debian.org/debian/pool/main/t/tcc/tcc_0.9.23.orig.tar.gz
#*
rm -Rv ~/usrc/tcc/
mkdir  ~/usrc/tcc/
cd $S/http/ftp.debian.org/debian/pool/main/t/tcc/
cp -v tcc_0.9.23* ~/usrc/tcc/
cd     ~/usrc/tcc/
dpkg-source -sn -x tcc_0.9.23-4.dsc
cd     ~/usrc/tcc/tcc-0.9.23/
dpkg-buildpackage -us -uc -b -rfakeroot     |& tee odb

#*
# (code-c-d "tcc" "~/usrc/tcc/tcc-0.9.23/" "tcc-doc")
# (find-tccfile "")
# (find-tccfile "tcc.c")
# (find-tccfile "examples/")
# (find-tccnode "Top")
# (find-tccnode "Libtcc")
# (find-tccnode "devel")
# (find-tccnode "devel" "Types")





# (find-node "(gcc)Macro Varargs")
# (find-node "(cpp)Macro Varargs")
# (find-node "(cpp)Stringification")
#*
eegcc <<<'
#define stringify(x) #x
#define FOO 0x99
main() { printf(stringify(FOO) "\n"); }
'

eec

#*




#####
#
# nasm (upstream)
# 2007feb06
#
#####

# «nasm-upstream»  (to ".nasm-upstream")
# http://ufpr.dl.sourceforge.net/sourceforge/nasm/nasm-0.98.39.tar.bz2
# (code-c-d "nasm" "~/usrc/nasm-0.98.39/")
# (find-nasmfile "")
#*
rm -Rv ~/usrc/nasm-0.98.39/
tar -C ~/usrc/ -xvjf \
  $S/http/ufpr.dl.sourceforge.net/sourceforge/nasm/nasm-0.98.39.tar.bz2
cd     ~/usrc/nasm-0.98.39/

./configure |& tee oc
make        |& tee om

#*



#####
#
# fasm
# 2008oct21
#
#####

# «fasm»  (to ".fasm")
# http://flatassembler.net/
# http://flatassembler.net/fasm-1.67.27.tgz
#*
rm -Rv ~/usrc/fasm/
tar -C ~/usrc/ -xvzf \
  $S/http/flatassembler.net/fasm-1.67.27.tgz
cd     ~/usrc/fasm/

#*
# (code-c-d "fasm" "~/usrc/fasm/")
# (find-fasmfile "")
# (find-fasmfile "fasm.txt")








#####
#
# Kernighan & Ritchie
# 2021sep18
#
#####

# «K-and-R»  (to ".K-and-R")
# (find-books "__comp/__comp.el" "kernighan-ritchie")
# (find-fline "~/books/__comp/kernighan_ritchie__the_C_programming_language.tar.gz")
# (code-c-d      "kandr" "~/usrc/the-c-programming-language/")
# (code-pdf-page "kandr" "~/usrc/the-c-programming-language/all.pdf")
# (code-pdf-text "kandr" "~/usrc/the-c-programming-language/all.pdf")
# (find-kandrpage)
# (find-kandrtext)
# (find-kandrfile "")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# (find-fline "~/usrc/the-c-programming-language/")
rm -Rv ~/usrc/the-c-programming-language/
mkdir  ~/usrc/the-c-programming-language/
tar -C ~/usrc/ -xvzf ~/books/__comp/kernighan_ritchie__the_C_programming_language.tar.gz
cd     ~/usrc/the-c-programming-language/

ls | grep html

A=( kandr
    preface preface1
    intro
    chapter1 chapter2 chapter3 chapter4 chapter5 chapter6 chapter7 chapter8
    appa appb appc
    )
for STEM in $A; do echo $STEM.html; done > /tmp/o
cat /tmp/o

# (find-angg ".emacs" "c2-2021-1-telegram")
prince -o all.pdf $(cat /tmp/o)





#####
#
# K-and-R-old
# 2021sep18
#
#####

# «K-and-R-old»  (to ".K-and-R-old")

#*
rm -Rv ~/usrc/the-c-programming-language/
tar -C ~/usrc/ -xvzf \
      ~/books/the-c-programming-language.tar.gz
cd     ~/usrc/the-c-programming-language/

#*
# (code-c-d "kandr" "~/usrc/the-c-programming-language/")
# (find-kandrfile "")
# (find-kandrw3m "kandr.html")
# (find-kandrw3m "chapter5.html")
# (find-kandrw3m "chapter5.html#s5.3" "pa = &a[0];")

There is one difference between an array name and a pointer that must
be kept in mind. A pointer is a variable, so pa=a and pa++ are legal.
But an array name is not a variable; constructions like a=pa and a++
are illegal.

When an array name is passed to a function, what is passed is the
location of the initial element. Within the called function, this
argument is a local variable, and so an array name parameter is a
pointer, that is, a variable containing an address. We can use this
fact to write another version of strlen, which computes the length of
a string.

# (find-kandrw3m "chapter6.html")
# (find-kandrw3m "chapter6.html#s6.3")
# (find-kandrw3m "chapter6.html#s6.3" "sizeof keytab / sizeof(keytab[0])")





#####
#
# stabs
# 2007aug31
#
#####

# «stabs»  (to ".stabs")
# (find-es "davinci")
# Can I use stabs to discover the sizeofs and offsets of structs?
#*
cd /tmp/
cat > foo.c <<'%%%'
#include <stdio.h>
struct s {
  int a;
  int b;
};
int main(void){
  struct s t;
  t.a = 1;
  t.b = 2;
  printf("Here: %i and %i\n", t.a, t.b);
  return 0;
}
%%%
gcc -g      -S -o foo.s  foo.c
gcc -gstabs -S -o foo.st foo.c
gcc -g      -c -o foo.o  foo.c
gcc -g         -o foo    foo.c
./foo

#*

* (eepitch-comint "gdb-foo" "gdb /tmp/foo")
* (eepitch-kill)
* (eepitch-comint "gdb-foo" "gdb /tmp/foo")
ptype struct s
quit

# (find-sh "cd /tmp/; objdump -xasf foo.o" "NEEDED")
# (find-sh "cd /tmp/; objdump -xasf foo.o" "Contents of section .debug_str:")
# (find-fline "/tmp/")
# (find-node "(stabs)Flow" "`-g'")
# (find-node "(stabs)Stabs Format")
# (find-node "(stabs)Assembly Code")
# (find-es "anatocc" "c-to-EsSo")
# (find-fline "/tmp/foo.s" ".string\t\"unsigned char\"")
# (find-fline "/tmp/foo.s")
# (find-fline "/tmp/foo.st")
# (find-gccnode "Debugging Options" "`-gstabs'")

# (find-sh "cd /tmp/; gcc -v -g -c -o foo.o  foo.c")

# (find-status   "binutils")
# (find-vldifile "binutils.list")
# (find-udfile   "binutils/")
# (find-status   "binutils-doc")
# (find-vldifile "binutils-doc.list")
# (find-udfile   "binutils-doc/")
# (find-node "(as)Stab")





#####
#
# Bruce Eckel: Thinking in C++
# 2007aug31
#
#####

# «eckelcpp»  (to ".eckelcpp")
# http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
# http://www.web42.com/eckel/TICPP-2nd-ed-Vol-one.zip
# http://www.web42.com/eckel/TICPP-2nd-ed-Vol-two.zip
#*
rm -Rv   ~/usrc/eckelcpp1/
rm -Rv   ~/usrc/eckelcpp2/
mkdir    ~/usrc/eckelcpp1/
mkdir    ~/usrc/eckelcpp2/

unzip -d ~/usrc/eckelcpp1/ \
  $S/http/www.web42.com/eckel/TICPP-2nd-ed-Vol-one.zip
unzip -d ~/usrc/eckelcpp2/ \
  $S/http/www.web42.com/eckel/TICPP-2nd-ed-Vol-two.zip

cd       ~/usrc/eckelcpp1/
unzip TIC2Vone-distribution/TICPP-2nd-ed-Vol-one-code.zip
unzip TIC2Vone-distribution/TICPP-2nd-ed-Vol-one-html.zip
# (find-sh "cmp --help")
for i in CompilerData.txt RevisionHistory.txt; do 
  cmp $i TIC2Vone-distribution/html/$i &&
  rm -v  TIC2Vone-distribution/html/$i
done
mv -iv TIC2Vone-distribution/html/* .

#*
# (code-c-d "eckelcpp1" "~/usrc/eckelcpp1/")
# (code-c-d "eckelcpp2" "~/usrc/eckelcpp2/")
# (find-eckelcpp1file "")
# (find-eckelcpp2file "")
# (find-eckelcpp1w3m "Contents.html")
# (find-eckelcpp2w3m "html/Contents.htm")





#####
#
# #warning
# 2007sep12
#
#####

# «warning»  (to ".warning")
# (find-status   "cpp-doc")
# (find-vldifile "cpp-doc.list")
# (find-udfile   "cpp-doc/")
# (find-status   "cpp-4.1-doc")
# (find-vldifile "cpp-4.1-doc.list")
# (find-udfile   "cpp-4.1-doc/")
# (find-node "(cpp)Diagnostics" "`#warning'")




#####
#
# alignment (in structs)
# 2007sep12
#
#####

# «alignment»  (to ".alignment")
# (find-es "davinci" "peek.lua:doc")
# (find-gccnode "Warning Options" "`-Wpacked'")
# (find-gccnode "Variable Attributes" "`aligned (ALIGNMENT)'")
# (find-gccnode "Variable Attributes" "\n\n`packed'")




#####
#
# stackdemo
# 2007dec20
#
#####

# «stackdemo»  (to ".stackdemo")
# (to "c-to-EsSo")
# (find-node "(gdb)Sample Session" "`backtrace'")
# (find-node "(gdb)Frames")
# (find-node "(gdb)Frames" "`frame ARGS'")
# (find-node "(gdb)Frames" "`select-frame'")
# (find-node "(gdb)Backtrace")
# (find-node "(gdb)Registers")
# (find-node "(gdb)Machine Code" "\n`disassemble'\n")
#*
rm -Rv /tmp/stackdemo/
mkdir  /tmp/stackdemo/
cd     /tmp/stackdemo/
cat > sd.c <<'%%%'
int d(int d1, int d2, ...) { int d3=3, d4=4;          return 'd'; }
int c(int c1, int c2, ...) { int c3=3, c4=4; d(1, 2); return 'c'; }
int b(int b1, int b2, ...) { int b3=3, b4=4; c(1, 2); return 'b'; }
int a(int a1, int a2, ...) { int a3=3, a4=4; b(1, 2); return 'a'; }
int main() {
  a(10, 20, 30, 40);
  return 0;
}
%%%
gcc -O0 -g -S -o sd.s sd.c
gcc -O0 -g    -o sd   sd.c

#*
# (find-fline "/tmp/stackdemo/sd.c")
# (find-fline "/tmp/stackdemo/sd.s")

(defun eepitch-gdb-sd ()
  (eepitch-gdb "*gud-sd*" "gdb --annotate=3 --quiet /tmp/stackdemo/sd"))
(defun eepitch-gdb-sd-kill ()
  (eepitch-gdb-kill "*gud-sd*"))

* (eepitch-gdb-sd)
* (eepitch-gdb-sd-kill)
* (eepitch-gdb-sd)
br d
run
bt
p &d1
p &d2
p &d3
p &d4
p d
frame
disassemble
frame 3
p &a1
p &a2
p &a2+1
p *(&a1)
p *(&a2)
p *(&a2+1)
p *(&a2+2)
# (find-fline "/tmp/stackdemo/sd.s" "\nd:")

p $fp
frame 0

#  _________ _________ _________ _________ __________ 
# |         |         |         |         |          |
# |  strack |  strack |  strack |  strack |  strack  |
# |  frame  |  frame  |  frame  |  frame  |  frame   |
# |  for d  |  for c  |  for b  |  for a  | for main |
# |_________|_________|_________|_________|__________|
#
# This is the stack frame for a, in details:

 _________ _________ __________ __________ 
|         |         |          |          |
|   a1    |   a2    | *(&a2+1) | *(&a2+2) |
|  (=10)  |  (=20)  |   (=30)  |   (=40)  |
|_________|_________|__________|__________|






# http://en.wikipedia.org/wiki/Executable_and_Linkable_Format
# (find-node "(binutils)readelf")
# (find-node "(as)")
# (find-node "(binutils)")
# (find-node "(ld)")
# (find-node "(binutils)c++filt")
# (find-node "(binutils)Index" "* demangling")
# (find-node "(binutils)nm")
# (find-node "(binutils)ar")
# (find-node "(binutils)ranlib")
# (find-node "(ld)Options" "`-Wl,'")
# (find-node "(ld)Options" "`-E'")
# (find-node "(ld)Options" "`-lARCHIVE'")
# (find-man "1 ld")




#####
#
# Updating glibc
# 2013jul13
#
#####

# «updating-glibc» (to ".updating-glibc")
# http://unix.stackexchange.com/questions/62940/how-to-run-new-software-without-updating-glibc?rq=1
# http://unix.stackexchange.com/questions/12522/installing-two-glibc-alongside-in-debian-ubuntu
# http://stackoverflow.com/questions/10863613/how-to-upgrade-glibc-from-version-2-13-to-2-15-on-debian

# (find-zsh "installeddebs | sort | grep libc")
# http://packages.debian.org/src:eglibc
# http://ftp.debian.org/debian/pool/main/e/eglibc/
# http://packages.debian.org/source/wheezy/eglibc

# (find-sh  "ldd /usr/bin/bc")
# (find-zsh "dmissing libc.so.6")
# (find-sh "grep-status 'Source: eglibc'")
# (find-status   "libc6")
# (find-vldifile "libc6:i386.list")
# (find-udfile   "libc6/")




#####
#
# UnderC
# 2014jul10
#
#####

# «UnderC» (to ".UnderC")
# http://home.mweb.co.za/sd/sdonovan/underc.html
# http://home.mweb.co.za/sd/sdonovan/faq.htm
# https://github.com/stevedonovan/UnderC
# (find-git-links "https://github.com/stevedonovan/UnderC" "underc")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# rm -Rfv ~/usrc/UnderC/
cd      ~/usrc/
git clone --depth 1 https://github.com/stevedonovan/UnderC
cd      ~/usrc/UnderC/
git pull --depth 1

cd      ~/usrc/UnderC/
git clean -dfx
git reset --hard

cd ~/usrc/UnderC/src/
./configure |& tee oc
make        |& tee om

# git pull
# (find-gitk  "~/usrc/UnderC/")
# (find-fline "~/usrc/")
# (find-fline "~/usrc/UnderC/")

# (code-c-d "underc" "~/usrc/UnderC/")
# (find-undercfile "")

# (find-undercfile "readme.md")




#####
#
# C4 - C in four functions
# 2017mai24
#
#####

# «c4» (to ".c4")
# https://github.com/rswier/c4
# https://github.com/rswier/c4/blob/master/c4.c
# https://github.com/EarlGray/c4
# https://news.ycombinator.com/item?id=22353532 C4: C in Four Functions (2014) (github.com/rswier)

# (find-git-links "https://github.com/rswier/c4" "c4")
# (code-c-d "c4" "~/usrc/c4/")
# (find-c4file "")
# (find-c4file "README.md")
# (find-c4file "c4.c")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd ~/usrc/c4/

gcc -o c4 c4.c
./c4 hello.c
./c4 -s hello.c

./c4 c4.c hello.c
./c4 c4.c c4.c hello.c


# https://kparc.com/b/
# https://kparc.com/b/readme.txt




#####
#
# lcc
# 2019sep21
#
#####

# «lcc» (to ".lcc")
https://en.wikipedia.org/wiki/LCC_(compiler)
https://github.com/drh/lcc
# (find-zsh "installeddebs | sort | grep lcc")
# (find-zsh "availabledebs | sort | grep lcc")




#####
#
# Dr. Dobb's Small-C Resource CD-ROM
# 2020nov23
#
#####

# «small-c-iso»  (to ".small-c-iso")
# http://www.deturbulator.org/jim.asp
# http://www.oxphoto.org/sc.zip
# https://news.ycombinator.com/item?id=18037370
#
# http://www.edm2.com/index.php/Small-C
# http://twimgs.com/ddj/sdmediagroup/images/sdm1123195158574/ddj_devnetwork_small_c.zip

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd /tmp/
rm -fv /tmp/ddj_devnetwork_small_c.iso
unzip $S/http/twimgs.com/ddj/sdmediagroup/images/sdm1123195158574/ddj_devnetwork_small_c.zip

sudo umount /tmp/small-c-iso/

rm -Rv /tmp/small-c-iso/
mkdir  /tmp/small-c-iso/
sudo mount -o loop,ro \
  /tmp/ddj_devnetwork_small_c.iso \
  /tmp/small-c-iso/

rm -fv    /tmp/small-c-iso.tgz
cd        /tmp/small-c-iso/
tar -cvzf /tmp/small-c-iso.tgz *

# (find-fline "/tmp/small-c-iso/")
# (find-fline "/tmp/small-c-iso/ARTICLES/CHAPS/")
# (find-fline "/tmp/small-c-iso/BOOK/CHAPS/")
# (find-fline "/tmp/small-c-iso/SMALLC/SMALLC22/READ.ME")
# (find-fline "/tmp/small-c-iso/SMALLC/SMALLC22/")
# file:///tmp/small-c-iso/ARTICLES/CHAPS/TOC.HTM
# file:///tmp/small-c-iso/BOOK/CHAPS/TOC1.HTM

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# (find-fline "/tmp/small-c/")
rm -Rv /tmp/small-c/
mkdir  /tmp/small-c/
cd     /tmp/small-c/

* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
chdir "/tmp/small-c/"
-- (find-fline       "/tmp/small-c-iso/SMALLC/SMALLC22/CLIB.ARC")
bigstr = ee_readfile "/tmp/small-c-iso/SMALLC/SMALLC22/CLIB.ARC"
bigstr = "\n"..bigstr:gsub("\r", "").."\n"
headers = {}
for p0,fname,n,p1 in bigstr:gmatch("\n()>>> ([!-~]+) ([0-9]+)\n()") do
  table.insert(headers, {p0,fname,n,p1})
end
table.insert(headers, {#bigstr})
PPV(headers)
files = {}
for i=1,#headers-1 do
  local fname,p1,p2 = headers[i][2], headers[i][4], headers[i+1][1]
  print(fname, p1, p2)
  table.insert(files, {fname, bigstr:sub(p1, p2)})
end

for i=1,#files do
  local fname,body = files[i][1], files[i][2]
  print(fname:lower(),#body)
  ee_writefile(fname:lower(), body)
end
-- (find-fline "/tmp/small-c/")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
sudo umount /tmp/small-c-iso/

# (find-fline "/tmp/small-c/")
# (find-fline "/tmp/small-c/fprintf.c")




#####
#
# readelf-runpath
# 2023jan18
#
#####

# «readelf-runpath»  (to ".readelf-runpath")
# (find-es "dos" "dosemu2-build-debian")
# (find-man "1 readelf")
# https://github.com/dosemu2/fdpp/issues/209#issuecomment-1386587016
# https://amir.rachum.com/blog/2016/09/17/shared-libraries/
# https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
# https://en.wikipedia.org/wiki/Rpath
# https://stackoverflow.com/questions/17142479/libraries-which-exist-in-a-binarys-elf-runpath-are-not-being-used
# https://wiki.debian.org/RpathIssue

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
readelf -d /usr/lib/dosemu/libplugin_fdpp.so
readelf -d /usr/lib/dosemu/libplugin_fdpp.so | grep RUNPATH

# (find-fline "/usr/lib/fdpp/")

# (find-sh "locate liblua")
# (find-sh "locate fdpp")
# (find-sh "locate fdpp | grep lib")
# (find-sh "locate fdpp | grep lib | grep -v edrx")

# (find-fline "/usr/lib/x86_64-linux-gnu/" "liblua5.1")
laf /usr/lib/x86_64-linux-gnu/ | grep liblua5.1
readelf -d /usr/lib/x86_64-linux-gnu/liblua5.1.so

cd /usr/lib/x86_64-linux-gnu/
for i in *.so; do echo $i; readelf -d $i | grep RUNPATH; done

cd /usr/lib/x86_64-linux-gnu/
for i in libLLVM*.so libpulse*.so; do
  echo $i
  readelf -d $i | grep RUNPATH
done

cd /usr/lib/x86_64-linux-gnu/
ldd libpulse.so

cd /tmp/
ldd /usr/lib/dosemu/libplugin_fdpp.so

# (find-sh "locate libfdpp.so")
# (find-sh "locate libplugin_fdpp.so")

ldd /usr/lib/fdpp/libfdpp.so

# (find-fline "/usr/lib/dosemu/")
# (find-fline "/usr/lib/fdpp/")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
readelf -d /usr/lib/dosemu/libplugin_fdpp.so
readelf -d /usr/lib/dosemu/libplugin_fdpp.so | grep RUNPATH

for i in /usr/lib/dosemu/*.so \
         /usr/lib/fdpp/*.so; do
  echo $i
  ldd $i
done > /tmp/o
grep found /tmp/o

# (find-fline "/tmp/o")

# (find-fline "$ASROOT/lib/x86_64-linux-gnu/" "libvorbis.so.0")
# (find-fline "/usr/lib/x86_64-linux-gnu/pulseaudio/")




#####
#
# dungeon-generator
# 2024feb20
#
#####

# «dungeon-generator»  (to ".dungeon-generator")
# https://gist.github.com/munificent/b1bcd969063da3e6c298be070a22b604
# https://news.ycombinator.com/item?id=39420385 A random dungeon generator that fits on a business card (2019) (gist.github.com)




http://lua-users.org/lists/lua-l/2012-12/msg00808.html Building Lua in Ubuntu 12




http://www.cs.princeton.edu/~rs/Algs3.c1-4/code.txt
http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/index.html

# [21.6] Is a Circle a kind-of an Ellipse?
# http://www.parashift.com/c++-faq-lite/proper-inheritance.html#faq-21.6


http://www.netfort.gr.jp/~dancer/software/binfmtc.html
http://neugierig.org/software/c-repl/



source for crt1, etc?

dynamic linking? ldd? Linking path?

stabs?

elf?

How does the kernel reads elf files?
And files with other "magic"?

Environment? Home dir?

Poised roadrunner style:
  (find-fline "/usr/bin/composeglyphs")

http://cluecc.sourceforge.net/
  Clue: an ANSI C compiler targeting high level languages

http://www.akkadia.org/drepper/dsohowto.pdf
  How to write shared libraries (Ulrich Drepper)

https://medium.com/@jinjizhang/what-happens-when-you-type-gcc-main-c-30f30b99ac7

https://gcc.gnu.org/legacy-ml/gcc-patches/2017-07/msg01448.html


https://news.ycombinator.com/item?id=28736238 “Static Linking Considered Harmful” Considered Harmful (gavinhoward.com)


https://github.com/ryanmjacobs/c

https://news.ycombinator.com/item?id=29291804 My Own Private Binary: An Idiosyncratic Introduction to Linux Kernel Modules (muppetlabs.com)
https://news.ycombinator.com/item?id=28026612 Learning that you can use unions in C for grouping things into namespaces (utoronto.ca)

https://github.com/rui314/mold/blob/main/docs/design.md
https://github.com/rui314/mold/blob/main/docs/design.md#a-brief-history-of-unix-and-the-unix-linker
https://www.ccs.neu.edu/home/amal/papers/linking-types.pdf

https://news.ycombinator.com/item?id=30942146 rand() may call malloc() (thingsquare.com)
https://news.ycombinator.com/item?id=30981549 C72: A port of the earliest C compiler to x86 (2021) (github.com/vegesm)
https://news.ycombinator.com/item?id=30991235 Show HN: How to compile C/C++ for WASM, pure Clang, no libs, no framework (github.com/ern0)
https://news.ycombinator.com/item?id=31244150 A minimal C compiler in x86 assembly (github.com/oriansj)

https://www.themarginalian.org/2022/06/18/william-blake-vs-the-world/?mc_cid=30280ca79f&mc_eid=64af6cf222

https://justine.lol/ape.html
https://justine.lol/cosmopolitan/index.html

https://news.ycombinator.com/item?id=32556048 A general overview of what happens before main() (2019) (embeddedartistry.com)
https://news.ycombinator.com/item?id=32642874 Supporting four operating systems in a 400 byte ELF executable (justine.lol)
https://news.ycombinator.com/item?id=33174996 Anatomy of Linux Dynamic Libraries (ibm.com)
https://news.ycombinator.com/item?id=33585154 AT&T Syntax versus Intel Syntax (mcgill.ca)
https://news.ycombinator.com/item?id=34183738 50 years of C, the good, the bad and the ugly [video] (ccc.de)
https://nullprogram.com/blog/2023/01/08/ SDL2 common mistakes and how to avoid them
https://www.nmattia.com/posts/2023-01-09-introduction-build-gcc-gnu.html
https://news.ycombinator.com/item?id=34367780 ABC: A C compiler for printable x86 (tom7.org)
https://eklitzke.org/stdout-buffering
https://news.ycombinator.com/item?id=35806237 Driving Compilers (fabiensanglard.net)

http://www.iro.umontreal.ca/~felipe/IFT2030-Automne2002/Complements/tinyc.c

https://xoreaxeax.com/b/heart 1014 byte polyglot binary
https://gms.tf/on-sprintf-fails.html
https://news.ycombinator.com/item?id=36064971 SectorC: A C Compiler in 512 bytes (xorvoid.com)
https://xorvoid.com/sectorc.html
https://buttondown.email/hillelwayne/archive/programming-language-perversity/
https://news.ycombinator.com/item?id=36839800 Never run ldd on unknown executables (catonmat.net)
https://news.ycombinator.com/item?id=37439125 Using LD_PRELOAD to cheat, inject features and investigate programs (rafalcieslak.wordpress.com)
https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/
http://cm.bell-labs.co/who/dmr/chist.html The Development of the C Language
https://iq.thc.org/how-does-linux-start-a-process
https://github.com/alexandru-dinu/igcc Interactive GCC
https://news.ycombinator.com/item?id=37685653 Interactive GCC (igcc) is a read-eval-print loop (REPL) for C/C++ (github.com/alexandru-dinu)
https://nedbatchelder.com/blog/202401/you_probably_dont_need_to_learn_c.html





#  Local Variables:
#  coding:               utf-8-unix
#  End: