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

Function symbol from assembler misses lowest bit set in Thumb mode #44205

Closed
agners opened this issue Feb 9, 2020 · 4 comments
Closed

Function symbol from assembler misses lowest bit set in Thumb mode #44205

agners opened this issue Feb 9, 2020 · 4 comments
Labels
backend:ARM bugzilla Issues migrated from bugzilla

Comments

@agners
Copy link
Contributor

agners commented Feb 9, 2020

Bugzilla Link 44860
Resolution FIXED
Resolved on Feb 24, 2021 14:22
Version 10.0
OS Linux
Blocks #4440
Attachments reproducer assembly
CC @jcai19,@DavidSpickett,@m-gupta,@nickdesaulniers,@smithp35

Extended Description

Using the .type directive to mark a label as a function in Thumb mode does not get the correct symbol table entry.

    .syntax unified
    .text
    .thumb

__setup_mmu:
it ne
blne __setup_mmu
.type __setup_mmu, %function // Move this line before __setup_mmu for correct behaviour.

llvm-mc --triple=armv7a-linux-gnueabihf blne.s -filetype=obj -o blne.o --arm-add-build-attributes
llvm-readelf --symbols blne.o

Symbol table '.symtab' contains 3 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t.0
2: 00000000 0 FUNC LOCAL DEFAULT 2 __setup_mmu

This has been observed when trying to build Linux for 32-bit ARM in Thumb2 mode. When the object file gets linked, the linker inserts a blx instruction which switches the CPU instruction set...

@DavidSpickett
Copy link
Collaborator

Not working (label then .type)

$ ./llvm-mc --triple=armv7a-linux-gnueabihf /tmp/test.s -filetype=obj -o /tmp/test.o --arm-add-build-attributes
$ ./llvm-readelf --symbols /tmp/test.o

Symbol table '.symtab' contains 3 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t.0
2: 00000000 0 FUNC LOCAL DEFAULT 2 __setup_mmu

Working (.type then label)

$ ./llvm-mc --triple=armv7a-linux-gnueabihf /tmp/test.s -filetype=obj -o /tmp/test.o --arm-add-build-attributes
$ ./llvm-readelf --symbols /tmp/test.o

Symbol table '.symtab' contains 3 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 NOTYPE LOCAL DEFAULT 2 $t.0
2: 00000001 0 FUNC LOCAL DEFAULT 2 __setup_mmu << value = 1 here

I assume the "value" here is the issue?

@smithp35
Copy link
Collaborator

Yes, the type STT_FUNC says the state (ARM/Thumb) of the symbol is determined by the bottom bit. So when STT_FUNC is set bit0 == 0 means the linker treats the symbol as ARM, bit 0 == 1 means Thumb. So this in effect causes the linker to change state incorrectly causing an illegal instruction.

@agners
Copy link
Contributor Author

agners commented Feb 20, 2020

Submitted a patch for review to fix this issue: https://reviews.llvm.org/D74927

@nickdesaulniers
Copy link
Member

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:ARM bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

4 participants