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

[Debian] Compiler bug: genassym.c -> assym.S #38

Open
wargio opened this issue May 13, 2016 · 10 comments
Open

[Debian] Compiler bug: genassym.c -> assym.S #38

wargio opened this issue May 13, 2016 · 10 comments

Comments

@wargio
Copy link

wargio commented May 13, 2016

I have a this problem on debian:
when i compile the assym.S is totally empty.
looks like the compiler removes the macro when it expands it.
file: https://github.com/darwin-on-arm/xnu/blob/master/osfmk/arm/genassym.c#L111

#define DECLARE(SYM,VAL) \
    __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))
#endif

i fixed it in this way:
on that file it becomes:

#define DECLARE(SYM,VAL) \
    __asm(".file \"#DEFINITION##define " SYM "       %0####\"" : : "n" ((u_int)(VAL)))
#endif

and i changed the makefile template:
File: https://github.com/darwin-on-arm/xnu/blob/master/osfmk/conf/Makefile.template#L123

$(_v)sed -e '/#DEFINITION#/!d' -e 's/^.*#DEFINITION#//' -e 's/\$$//' -e 'p' -e 's/#//2' -e 's/[^A-Za-z0-9_]*\([A-Za-z0-9_]*\)/ \1_NUM/2' genassym.o > ${@}

to

$(_v)sed -e '/.file\s*\"#DEFINITION#/!d' -e 's/^.*#DEFINITION#//' -e 's/####\"//' -e 's/\$$//' -e 'p' -e 's/#//2' -e 's/[^A-Za-z0-9_]*\([A-Za-z0-9_]*\)/ \1_NUM/2' genassym.o > ${@}

Anybody knows a better why to fix this?

@wargio wargio changed the title genassym.c -> assym.S [Debian] Compiler bug: genassym.c -> assym.S May 13, 2016
@nightsuns
Copy link

below is my fix:


osfmk/arm/genassym.c | 7 +++++--
osfmk/conf/Makefile.template | 4 +++-
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/osfmk/arm/genassym.c b/osfmk/arm/genassym.c
index 9b3d063..d3f46d9 100644
--- a/osfmk/arm/genassym.c
+++ b/osfmk/arm/genassym.c
@@ -108,8 +108,11 @@
#define DECLARE(SYM,VAL)
__asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL)))
#else
+//#define DECLARE(SYM,VAL)
+// __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))
#define DECLARE(SYM,VAL) \

  • __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL)))

  •    __asm("DEFINITION__define__" SYM ":\t .ascii \"%0\"" : : "n"  ((u_int)(VAL)))
    

    #endif

    int main(int argc, char *_argv);
    @@ -129,7 +132,7 @@ int main(int argc, char *_argv)
    DECLARE("MUTEX_STATE", offsetof(lck_mtx_t *, lck_mtx_state));

    DECLARE("MUTEX_IND", LCK_MTX_TAG_INDIRECT);

  • DECLARE("MUTEX_PTR", offsetof(lck_mtx_t *, lck_mtx_ptr));
    +// DECLARE("MUTEX_PTR", offsetof(lck_mtx_t *, lck_mtx_ptr));
    DECLARE("MUTEX_ASSERT_OWNED", LCK_MTX_ASSERT_OWNED);
    DECLARE("MUTEX_ASSERT_NOTOWNED", LCK_MTX_ASSERT_NOTOWNED);
    DECLARE("GRP_MTX_STAT_UTIL",
    diff --git a/osfmk/conf/Makefile.template b/osfmk/conf/Makefile.template
    index c39e844..a04f213 100644
    --- a/osfmk/conf/Makefile.template
    +++ b/osfmk/conf/Makefile.template
    @@ -117,10 +117,12 @@ GENASSYM_LOCATION = i386
    endif

genassym.o: $(SOURCE_DIR)/$(COMPONENT)/$(GENASSYM_LOCATION)/genassym.c

  • @echo $(_v)${KCC} $(subst -flto,,${CFLAGS}) -MD ${_HOST_EXTRA_CFLAGS} -S -o ${@} -c ${INCFLAGS} $<
    $(_v)${KCC} $(subst -flto,,${CFLAGS}) -MD ${_HOST_EXTRA_CFLAGS} -S -o ${@} -c ${INCFLAGS} $<

assym.s: genassym.o

  • $(v)sed -e '/#DEFINITION#/!d' -e 's/^.*#DEFINITION#//' -e 's/$$//' -e 'p' -e 's/#//2' -e 's/[^A-Za-z0-9_]([A-Za-z0-9_])/ \1_NUM/2' genassym.o > ${@}
    +# $(v)sed -e '/#DEFINITION#/!d' -e 's/^.*#DEFINITION#//' -e 's/$$//' -e 'p' -e 's/#//2' -e 's/[^A-Za-z0-9_]([A-Za-z0-9
    ]_)/ \1_NUM/2' genassym.o > ${@}
  • $(v)sed -e '/^[[:space:]]*DEFINITION__define_/!d;{N;s/\n//;}' -e 's/^[[:space:]]DEFINITION__define_([^:]):.ascii."[$$]([-0-9#])".$$/#define \1 \2/' -e 'p' -e 's/#//2' -e 's/^[[:space:]]#define ([A-Za-z0-9])[[:space:]][$$#]([-0-9]).*$$/#define \1_NUM \2/' genassym.o > $@

${SOBJS}: assym.s

2.7.4

@spotlightishere
Copy link

@nightsuns, can you please post the patch in a code block so I can copy/paste it? GitHub's markdown took over it 😃

@johnothwolo
Copy link

Hey @nightsuns, please paste a readable patch.

@spotlightishere
Copy link

I'm glad I got a notification from this issue. I was working with the GitHub API at the time and had the idea of just getting the raw message. I don't know how to escape backticks on Github and this patch appears to have some... so, I'll just show you how to get the raw answer.

curl -i "https://api.github.com/repos/darwin-on-arm/xnu/issues/38/comments"

It'd be under the body element in the JSON response. You'll have to replace \n with actual newlines.

@wargio
Copy link
Author

wargio commented Jun 20, 2017

https://github.com/wargio/xnu/commit/b17d2a5f396161467a3f9f719b76721ad6a2474b.patch

@wargio
Copy link
Author

wargio commented Jun 20, 2017

that's my patch

@johnothwolo
Copy link

johnothwolo commented Jun 20, 2017

Oh thanks @wargio, do you think it would be possible to emulate ios with this kernel?

@johnothwolo
Copy link

johnothwolo commented Jun 20, 2017

Somehow the kernel is still not building, I followed the instructions and the patch didn't work. The assym.s file is empty in the Build folder. I'm kinda new at this stuff....

@wargio
Copy link
Author

wargio commented Jun 20, 2017

try with my fork.

@johnothwolo
Copy link

johnothwolo commented Jun 20, 2017

It failed with the same error. I'm on macOS 10.12.6. I know enough c and I understand what the makefile template was trying to do, but i'm not fluent with unix commands. I checked the build without the patch:

sed -e '/#DEFINITION#/!d' -e 's/^.*#DEFINITION#//' -e 's/\$$//' -e 'p' -e 's/#//2' -e 's/[^A-Za-z0-9_]*\([A-Za-z0-9_]*\)/ \1_NUM/2' genassym.o >${@}

And got some definitions which were incomplete or something, but when i tried with the patch:

sed -e '/.file\s*\"#DEFINITION#/!d' -e 's/^.*#DEFINITION#//' -e 's/####\"//' -e 's/\$$//' -e 'p' -e 's/#//2' -e 's/[^A-Za-z0-9_]*\([A-Za-z0-9_]*\)/ \1_NUM/2' genassym.o > ${@}

assym.S ended up empty.

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

No branches or pull requests

4 participants