Closed sudhackar closed 9 months ago
hmm. The build fails for macos. I'll test more.
So without disabling pie I am not able to get nasm to call libc functions on linux
Symbol `exit' causes overflow in R_X86_64_PC32 relocation
I saw some workarounds like using wrt
with ..plt
or ..got
to call libc functions in presence of pie - but that'd fail on mac. See build
linked_list.asm:12: error: symbol `..plt' undefined
In current state it works fine on my mac - intel, 2019, Big Sur 11.6.3 and ubuntu/alpine docker in this state. Additionally I tested a change with plt too.
Thanks for submitting this PR! @bergjohan Could you look at this PR?
I'll try to take a look tomorrow
Thanks for the PR, nice work! A few thoughts:
When I created this track, I avoided exercises with dynamic allocation, since it's very OS dependent. I'm not sure how I feel about forcing the student to use the C standard library in an assembly track. The student would have to learn how to use the functions malloc
and free
, which might not be what you want/expect when working through an assembly track. Although, the test cases are written in C, so a basic knowledge of C is pretty much required to get started.
struct list_node
and struct list
are defined in the .c test file, but never actually used, we could just as well use something like typedef void *ll_handle
. I assume you'd like the student to follow the layout of these structs in the exercise. Maybe it would be better to add a struc
as a starting point in the .asm file with an example layout: https://www.nasm.us/xdoc/2.15.05/html/nasmdoc5.html#section-5.9
To avoid dynamic memory allocation, maybe we could pre allocate some memory in the .bss section, enough to handle the test cases, i.e have the linked list be fixed size. Something like memory: resb 1024 ; reserve 1024 bytes for the linked list
.
This is just some thoughts to get a discussion going on what the best way to implement this exercise would be.
Calling malloc
and free
from the library actually created a couple of problems while testing. So I'd agree about that. Same goes about making syscalls - it makes them limited to a platform.
I'll move the struct defs from c to asm - that makes sense.
@bergjohan Did these changes - based on your thoughts
struc
in the solution templatemalloc
and free
instancesThanks, great work!
Some additional thoughts:
currm
, m
, curridx
and global
to the .bss section, since they're static data and it would make them zero initialized by default.currm
is unused.nodes
instead of glob
, and something like list
instead of m
. That would probably collide with the STRUC though, maybe capitalize the STRUC names, and call them Node
and List
to separate them from the variables. Or maybe get rid of the list STRUC and use two separate variables for first
and last
.list_create()
and list_destroy()
to simplify the exercise, and make it clear that the there's only a single list.Since we only support one list at a time, it feels a bit redundant to pass around a list pointer. I think we could get rid of list_create() and list_destroy() to simplify the exercise, and make it clear that the there's only a single list.
The list needs to be a new one for each test. The tests will fail if we don't clear the state from last test - setUp
and tearDown
are called before and after each test.
Yeah, I was thinking we could add a function, list_clear()
, that clears the list, which could be called in setUp
.
If you think the current way is better, that's fine, I'm just trying to think of ways to simplify the exercise and make it as clear as possible to the student what's expected of them.
IMO a tearDown
function to clear all pointers would help clear dangling references for the students - I'll add additional documentation to make it clearer
My bad, a call to list_clear()
would be better in tearDown
. My thoughts were, list_clear()
would clear all static memory for the list, i.e. all the pointers would be set to zero. Maybe list_reset()
would be a better name.
I have made changes for the first 4 points. I still feel that keeping the List as a struct with a couple of pointers is OK.
For the tearDown
change I'll do it in a while
Ah Its been a "while". Sorry I totally forgot about this - the current change should do everything you suggested @bergjohan
Adding linked list exercise from https://github.com/exercism/problem-specifications/tree/main/exercises/linked-list
Example solution passed the build