- step 1. doing the main parts of pgu i want to do
- step 2. doing the main parts of pgu i don't
- step 3. doing the exercises
- step 4. try implementing basic x11? or gnome?
- research
nasm -@rn FILE # response file
nasm -f elf64 -g -w+all FILE # actually rnremove -g if not debugging;
-g is helpful in gdb
# this can happen in the ./linktest directory
nasm -f elf64 -o linktest_asm.o linktest_asm.asm
gcc -c -o linktest_c.o linktest_c.c -O0
gcc -no-pie -o linktest linktest_c.o linktest_asm.o -lcthis is a deprecated behaviour, but the warning still pops
up for now: missing .note.GNU-stack section implies executable stack.
to fix, add to asm:
section .note.GNU-stack noalloc noexec nowrite progbitsalso, without -no-pie, it uses Scrt1.o, which is made
for shared libraries.
note: gcc is more portable than ld!
gcc -print-file-name can be used for finding the actual files
gcc talks about:
# after compiling FILE.asm w/ nasm
CRT1=$(gcc -print-file-name=crt1.o)
CRTI=$(gcc -print-file-name=crti.o)
CRTN=$(gcc -print-file-name=crtn.o)
LDD=$(gcc -print-file-name=ld-linux-x86-64.so.2)
ld "$CRT1" "$CRTI" \
FILE.o -lc \
"$CRTN" \
-dynamic-linker "$LDD" \
-L . \
-o EXECfor me, the printed file names were all basically:
/usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/FILE
# which becomes
/usr/lib/x86_64-linux-gnu/FILE
where FILE was the argument passed to gcc.
I can also use /lib64/ld-linux-x86-64.so.2
use ld -shared to make a .so instead of a normal .o.
libNAME.so allows you to use the flag -lNAME to link it.
although, you should use -L . if it is local only.
use -rpath to add a directory to search for libraries,
or set $LD_LIBRARY_PATH to them colon-seperated. it is
usually empty by default, and it will be checked if not empty.
nm and objdump are useful! so is readelf and ldd.
ld -r combines objects.
ar archives static objects?
the c calling convention in convoluted, but here is a summary:
- word inputs are rdi, rsi, rdx, rcx, r8, and r9.
- word outputs are rax and rdx
- word inputs, rax, r9, and r10 are volatile: they are saved by the caller, not callee.
- floating point uses sse: in = xmm0-7, and out = xmm0 and xmm1
- al has the amount of floats used?
- long double is x87: input is the stack, and out = st0 and st1
- all sse and x87 is volatile
- rest of registers are non-volatile: callee saves
- obviously, if all registers are full, use stack
because of crt1.o, you use main instead of _start.
- optimize AFTER the product is clean
- everything is documented
- as well as works by the documentation
- and the code is modular
- try not to in early development
- use a profiler tool, like
gprof(standard) - local optimization is about the program specifically
- e.g. fastest instructions/methods
- precomputing calculations
- caching results
- location of data (where it is -> how fast to access)
- register usage
- inline functions (macros)
- optimized instructions (
mov,0->xor,deccx;jz->loop) - addressing modes (
[const]->[reg]->[reg + const * reg]) - data alignment (less variation of data sizes)
- global optimization is about what the program uses
- e.g. inputs and outputs
- usually about restructuring rather than solving
- parallelization
- statelessness
COMMAND | code - opens the piped output into a tab in the same window.
ds:0x... in the object/elf dump means it is somewhat external to the actual code. it is still acknowledged by the dumper, of course.
ld --dynamic-linker /lib64/ld-linux-x86-64.so.2 add_year_ip.o librecords.so -rpath $PWD -o e- Programming from the Ground Up by Jonathan Bartlett
- Introduction to Algorithms by Thomas H. Cormen, Charles E. Leiserson, and Ronald L. Rivest
- The Art of Computer Programming by Donald Knuth (3 volume set - volume 1 is the most important)
- Programming Languages by Samuel N. Kamin
- Modern Operating Systems by Andrew Tanenbaum
- Linkers and Loaders by John Levine
- Computer Organization and Design: The Hardware/Software Interface by David Patterson and John Hennessy
- How to Design Programs by Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shiram Krishnamurthi, available online at http://www.htdp.org/
- Simply Scheme: An Introduction to Computer Science by Brian Harvey and Matthew Wright
- How to Think Like a Computer Scientist: Learning with Python by Allen Downey, Jeff Elkner, and Chris Meyers, available online at http://www.greenteapress.com/thinkpython/
- Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman with Julie Sussman, available online at http://mitpress.mit.edu/sicp/
- Design Patterns by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
- What not How: The Rules Approach to Application Development by Chris Date
- The Algorithm Design Manual by Steve Skiena
- Programming Language Pragmatics by Michael Scott
- Essentials of Programming Languages by Daniel P. Friedman, Mitchell Wand, and Christopher T. Haynes
- Programming Perl by Larry Wall, Tom Christiansen, and Jon Orwant
- Common LISP: The Language by Guy R. Steele
- ANSI Common LISP by Paul Graham
- The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie
- The Waite Group’s C Primer Plus by Stephen Prata
- The C++ Programming Language by Bjarne Stroustrup
- Thinking in Java by Bruce Eckel, available online at http://www.mindview.net/Books/TIJ/
- The Scheme Programming Language by Kent Dybvig
- Linux Assembly Language Programming by Bob Neveln
- https://brettapitz.github.io/posts/groundup1/
- helped with getting started on nasm
- https://nasm.us/
- docs on nasm
- https://www.chromium.org/chromium-os/developer-library/reference/linux-constants/syscalls/
- syscalls
- https://x64.syscall.sh/
- https://gaultier.github.io/blog/x11_x64
- X11 (graphics) in assembly... crazy!!! 🤯
manfornasm:ld:objdump:readelf:patchelf:ldd:nm:ar- https://graphics.stanford.edu/~seander/bithacks.html
- kinda faster alternatives to normal instructions
- sometimes very c oriented
- http://www.sandpile.org/
- more on intel and amd and stuff
- https://www.cs.yale.edu/homes/perlis-alan/quotes.html
- idk
- https://gist.github.com/jxu/c3c31504ec75e3862849c37183e03ced
- summary: (
_means a normal number, so0instead of$0)[r] (%)[r+r] (%,%)[r+c] _(%)[r+c+r] _(%,%)[r+r*c] (%,%,_)[c+r*c] _(,%,_)[r+c*r+c] _(%,%,_)(really[c+r+c*r])
- summary: (