Skip to content

Instantly share code, notes, and snippets.

@msgodf
Last active July 31, 2016 07:47
Show Gist options
  • Save msgodf/54e81c1fb00bb54d4202c60db8cdd8fa to your computer and use it in GitHub Desktop.
Save msgodf/54e81c1fb00bb54d4202c60db8cdd8fa to your computer and use it in GitHub Desktop.

Done

  • Compile AmiTCP example with only -lsocket
  • Setup nginx on rpi to share files between Amiga and rpi

Todo

  • Try opening v3 of bsdsocket.library and see whether httpget still works.
  • Get a working version of curl on the Amiga.
  • Use AmiTCP specific functions, not just bsdsocket.library ones
  • Watcher script calling make in compiler container running on pi.

Learned

How to debug linking

  • LD_DEBUG=all
  • The argument -Wl,--verbose to gcc shows which libraries are being linked, and the symbols from them.
  • I was wondering which libsocket.a it was pulling in when using -lsocket, and this showed it was coming from /opt/toolchain/m68k-amigaos/libnix/lib/libm020/libnix/libsocket.a
  • Then I wondered what libsocket.a had in it. So I used m68k-amigaos-objdump --section-headers /opt/toolchain/m68k-amigaos/libnix/lib/libm020/libnix/libsocket.a and this showed me the .o parts that the library contained.
  • bsdsocket.library isn't a disk based library - it's loaded into memory by AmiTCP.
  • The AmiTCP examples don't have a main() function, but a begin() function. The linker can be told to use this instead with -Wl,-e_begin.
  • The objcopy utility in GNU BinUtils can be used to change the entry point of a binary: http://stackoverflow.com/questions/7494244/how-to-change-entry-point-of-c-program-with-gcc
  • EasyNet is running AmiTCP 3, so when I compiled the httpget example to actually open bsdsocket.library then it failed.
  • They sell EasyNet Pro, as they're licensed to sell AmiTCP 4.x
  • When I compiled httpget with the optimization flag -Os (or of the -O options) it gave me a linker error saying it couldn't find TimerBase. I looked at the optimization flags for GCC 2.95.3 at http://www.sbras.ru/cgi-bin/www/unix_help/unix-man?cc+1, but ended up finding out about the -Q option on GCC that shows you what flags it's actually using, i.e. when you use different -O options.
-m68020 -mc68020 -mbitfield -m68332 -mcpu32 -fdefer-pop
 -fomit-frame-pointer -fcse-follow-jumps -fcse-skip-blocks
 -fexpensive-optimizations -fthread-jumps -fstrength-reduce -fpeephole
 -fforce-mem -ffunction-cse -finline -fkeep-static-consts -fcaller-saves
 -fpcc-struct-return -fgcse -frerun-cse-after-loop -frerun-loop-opt
 -fsjlj-exceptions -fcommon -fgnu-linker -fregmove -foptimize-register-move
 -fargument-alias -fident
  • The toolchain makefile uses the optimization option -Os (which is why I'm using it), but I wasn't sure which option was causing it to fail. When I manually specified all the options that it said it was using then it failed with a different error: "cannot open -lsocket". I assume because it uses different libraries. And -Q told me that it was actually using a different set of flags than I specified anyway:
 -fcse-skip-blocks -fexpensive-optimizations -fthread-jumps
 -fstrength-reduce -fpeephole -fforce-mem -ffunction-cse
 -fkeep-static-consts -fcaller-saves -fpcc-struct-return -fgcse
 -frerun-cse-after-loop -frerun-loop-opt -fsjlj-exceptions -fcommon
 -fgnu-linker -fregmove -foptimize-register-move -fargument-alias -fident
 -m68332 -mcpu32```
* I think it can't find libsocket.a because it's removed the `-m68020` option, and so isn't specifying the correct target. I think the `-mc68020` option is overriding it and causing it to remove the option. And `-Os` also does this. So I just need to specify them manually without the `-mc68020` option and it all works.
* ~~The `httpget` example stops working when I try using the original entry point (`begin`). Well, it takes an argument, and complains if it isn't provided, but doesn't do anything when given a URL.~~
* It works, if I use the correct port (8080) :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment