Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dinosaure
Copy link
Collaborator

Fix #562 (/cc @palainp)

@palainp
Copy link
Contributor

palainp commented Mar 1, 2024

Thank you @dinosaure . As @Kensan pointed in #562 I though about adding something rather than removing the /DISCARD/ part. It seems that it's mandatory to add the lines in the asm files and not in thge linker script. About this PR and the change proposed at https://github.com/codelabs-ch/solo5/tree/asm-noexec-stack, when I compile qubes-mirage-firewall, I have:

  • current head
/usr/bin/ld: warning: /home/user/.opam/4.14.1/bin/../lib/x86_64-solo5-none-static/solo5_xen.o: requires executable stack (because the .note.GNU-stack section is executable)
  • this PR
/usr/bin/ld: warning: /home/user/.opam/4.14.1/bin/../lib/x86_64-solo5-none-static/solo5_xen.o: requires executable stack (because the .note.GNU-stack section is executable)
  • the commit proposed that add some asm notes
/usr/bin/ld: warning: amd64.o: missing .note.GNU-stack section implies executable stack
/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker

That warning comes from the caml compiler directory, so it might be relevant to also investigate there.

So to me the issue should be fixed by https://github.com/codelabs-ch/solo5/tree/asm-noexec-stack :)

@dinosaure
Copy link
Collaborator Author

Yes, I agree to put the .note.GNUinto assembly code and discard it at the link time 👍.

That warning comes from the caml compiler directory, so it might be relevant to also investigate there.

You mean with ocaml-solo5? Not sure to understand well this warning. The warning will be deleted then in next versions of the linker?

@palainp
Copy link
Contributor

palainp commented Mar 3, 2024

You mean with ocaml-solo5? Not sure to understand well this warning. The warning will be deleted then in next versions of the linker?

The only amd64.o I've found is in ~/.opam/default/.opam-switch/build/ocaml-solo5.xxx/ocaml/runtime/ and ocaml has assembly files (e.g. https://github.com/ocaml/ocaml/blob/trunk/runtime/amd64.S). It seems that this warning has been recently added and reading https://discuss.ocaml.org/t/ld-error-missing-note-gnu-stack-section/12478 leave me thinking about adding the directive to ocaml-solo5.

So to me this is unrelated to solo5, the commit proposed by @Kensan LGTM.

To move forward I wonder if the best is to add (flags (:standard -cclib "-z noexecstack")) in ocaml-solo5 (if possible) or PR at ocaml to add a similar .section .note.GNU-stack,"",%progbits in the asm files? EDIT: As it seems there's no issue about that in the ocaml repository, it's probably relevant to ocaml-solo5 :)

Add .note.GNU-stack section to assembly files which recent ld versions
require to determine whether an executable stack is required. If no such
ELF section is present, the linker assumes that the stack needs
executable rights. See also [1].

[1] - https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart
@dinosaure
Copy link
Collaborator Author

To move forward I wonder if the best is to add (flags (:standard -cclib "-z noexecstack")) in ocaml-solo5 (if possible) or PR at ocaml to add a similar .section .note.GNU-stack,"",%progbits in the asm files? EDIT: As it seems there's no issue about that in the ocaml repository, it's probably relevant to ocaml-solo5 :)

So, I will let this PR opens but we probably should check if the warning continues to appear if we update ocaml-solo5.

@hannesm
Copy link
Contributor

hannesm commented Oct 9, 2024

Is there any solution for this PR? Should it be included in solo5, or can it be left out (and closed)?

@shym
Copy link
Contributor

shym commented Mar 4, 2025

I would suggest to follow the same strategy than what was merged in the compiler in [ocaml/ocaml#13735], namely to do just as the C compiler does: the logic the C compiler uses to determine whether it should output the .note.GNU-stack is more complex than it appears (I looked into clang at least, I don’t remember for GCC) and they are surprising special cases (% is not always the symbol chosen by the compiler, for instance), so copying the C compiler output is a lot safer.
So, we could do so by adding in bindings/GNUmakefile:

noexecstack.c:
	printf 'int f() {\n  return 0;\n}\n' > $@

noexecstack.s: noexecstack.c
	$(CC) $(CFLAGS) $(CPPFLAGS) -S $< -o $@

noexecstack.h: noexecstack.s
	grep -F .note.GNU-stack $< > $@

and adding #include "noexecstack.h" in the .S files instead of using directly the note.

@dinosaure
Copy link
Collaborator Author

Thanks for your solution. I still think that this PR is not yet needed for Solo5 as we discovered. I will still keep this PR open the time that we get the same issue again but let's keep Solo5 simple as long as we don't need to deal with .note.GNU-stack.

@hannesm
Copy link
Contributor

hannesm commented Oct 20, 2025

I'm still uncertain what we need to do here. Is #562 still an issue, and is there a reasonable fix (this PR, or a different one)?

@dinosaure
Copy link
Collaborator Author

I still think that the issue is much more related to ocaml-solo5 than solo5 itself. I noticed the error only when it's about building an unikernel with ocaml-solo5 and never saw this error when it's about just compile a (C?) unikernel with Solo5. So, I'm not sure that we should merge it and probably just double check GCC versions used, if it's about ocaml-solo5 or if we can reproduce the error with a simpe C unikernel.

@hannesm
Copy link
Contributor

hannesm commented Oct 23, 2025

In our CI, we see the warnings. So I'd guess it is about solo5. Also, @Kensan proposed in #562 (comment) a different solution.

@shym
Copy link
Contributor

shym commented Oct 23, 2025

The issue is really in Solo5. The patches to OCaml fixed this issue in the code generated by the compiler. The fix in the compiler is doing something similar to what I wrote in my comment above: it calls the C compiler and mimicks its behaviour later on.

@hannesm
Copy link
Contributor

hannesm commented Oct 23, 2025

@shym oh. or maybe you have a good idea for how to patch solo5? It may be based on @Kensan branch, or your idea from above. Any PR that fixes the warning would be great.

@shym
Copy link
Contributor

shym commented Oct 23, 2025

Any PR that fixes the warning would be great.

#619 is what I had in mind.

@dinosaure dinosaure closed this Oct 27, 2025
dinosaure added a commit to dinosaure/opam-repository that referenced this pull request Oct 27, 2025
- Fix compilation on OpenBSD about `#ifdef` (@omegametabroccolo, @hannesm, @reynir, Solo5/solo5#614, related with Solo5/solo5#600)
- Add GitHub actions to test Solo5 on different platforms (@hannesm, Solo5/solo5#616, Solo5/solo5#617 & Solo5/solo5#540)
- Do not use `-Wstringopt-overflow` when we use `clang` for `test_ssp` (@hannesm, Solo5/solo5#607)
- Show errors and exit instead of `assert false` (@shym, @edwintorok, @hannesm, @reynir, Solo5/solo5#613 & Solo5/solo5#612)
- Define `.note.GNU-stack` when it's needed (@shym, @Kensan, @hannesm, @palainp, @dinosaure, Solo5/solo5#619, Solo5/solo5#570 & Solo5/solo5#562)
- Detect MTU on TAP interface for hvt, spt and virtio (@reynir, @hannesm, @dinosaure, Solo5/solo5#605 & Solo5/solo5#606)
@hannesm hannesm deleted the no-discard branch October 27, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GNU ld wants executable stack

6 participants