Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] build failure on arm ELF targets: %progbits must be used instead of @progbits #4385

Closed
clausecker opened this issue Oct 7, 2021 · 6 comments
Labels

Comments

@clausecker
Copy link
Contributor

Version of Kakoune

v2020.09.01

Reproducer

Compile Kakoune on an arm/ELF target with clang (may reproduce with gcc, too). I tried to build the version shipped with the FreeBSD ports.

Outcome

Build failure:

c++ -I/usr/local/include -O2 -pipe -fstack-protector-strong -fno-strict-aliasing   -pedantic -std=c++17 -g -Wall -Wextra -Wno-unused-parameter -Wno-sign-compare -Wno-address -frelaxed-template-template-args -MD -MP -MF .main.opt.d -c -o .main.opt.o main.cc
<inline asm>:2:41: error: expected '%<type>' or "<type>"
.pushsection ".debug_gdb_scripts", "MS",@progbits,1
                                        ^
<inline asm>:10:12: error: .popsection without corresponding .pushsection
.popsection
           ^
2 errors generated.
gmake[1]: *** [Makefile:112: .main.opt.o] Error 1
gmake[1]: Leaving directory '/wrkdirs/usr/ports/editors/kakoune/work/kakoune-2020.09.01/src'

Expectations

Successful build.

Additional information

The main file has a piece of assembly to integrate debugging scripts. The first line expands to something like

.pushsection ".debug_gdb_scripts", "MS",@progbits,1

which is fine except on ARM where @ is a comment character and % must be used instead. Other targets may require characters other than @, too (see GNU as manual).

To fix this, perhaps add a configure test to check if @ or % is the right character to use here and insert the right one. Or just hard code the use of % on ARM for now.

@clausecker clausecker added the bug label Oct 7, 2021
@mawww
Copy link
Owner

mawww commented Oct 9, 2021

I occasionally build Kakoune on a raspberry pi, and never had this issue, so I dont think it reproduces with gcc. I guess we will need to introduce some preprocessor magic in here to fix that unfortunate inconsistency.

@mawww
Copy link
Owner

mawww commented Oct 23, 2021

I tried to build with clang in termux on my ARM based phone and did not get any issue, it looks like FreeBSD also uses GNU assembler so I am not sure why you get that issue and if this has been changed in more recent gas release. I would be nice to understand exactly in which circumstances this happens.

@clausecker
Copy link
Contributor Author

@mawww Is your phone arm64 based? This issue only occurs on 32 bit ARM, not on the 64 bit variant.

it looks like FreeBSD also uses GNU assembler so I am not sure why you get that issue and if this has been changed in more recent gas release.

LLVM by default uses its own internal assembler. It is possible to force use of an external GNU assembler, but I don't think that would make a difference (I can try if you like).

@mawww
Copy link
Owner

mawww commented Oct 24, 2021

I dont have a 32-bit ARM device available unfortunately, so I cannot reproduce/test. I will accept a PR for this but cant do it myself blindly.

My preference would be to #define the PROGBITS token accordingly, then use preprocessor string concatenation to insert it (so hopefully just doing )" PROGBITS R"( in place of @progbits would do the trick.

As said earlier, happy to merge a PR if you can validate such a change.

@clausecker
Copy link
Contributor Author

Ok, I'll look into writing a patch for you.

@clausecker
Copy link
Contributor Author

This patch fixes the issue for me. I will submit it to the FreeBSD ports collection. Feel free to upstream it.

--- src/main.cc.orig	2021-10-25 11:31:24 UTC
+++ src/main.cc
@@ -1249,8 +1249,12 @@ int main(int argc, char* argv[])
 }
 
 #if defined(__ELF__)
-asm(R"(
-.pushsection ".debug_gdb_scripts", "MS",@progbits,1
+#ifdef __arm__
+# define PROGBITS "%progbits"
+#else
+# define PROGBITS "@progbits"
+#endif
+asm(".pushsection \".debug_gdb_scripts\", \"MS\"," PROGBITS ",1" R"(
 .byte 4
 .ascii "kakoune-inline-gdb.py\n"
 .ascii "import os.path\n"

freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this issue Oct 25, 2021
freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this issue Oct 25, 2021
ocochard pushed a commit to ocochard/freebsd-ports that referenced this issue Oct 28, 2021
@mawww mawww closed this as completed Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants