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

Add LoongArch Support #1

Open
wants to merge 2 commits into
base: la64/master
Choose a base branch
from
Open

Add LoongArch Support #1

wants to merge 2 commits into from

Conversation

loongson-zn
Copy link
Collaborator

增加LA的支持,please review,thanks! @loongarch64/dev-team

@loongson-zn
Copy link
Collaborator Author

修改前输出:

[loongson@localhost LIEF]$ python3.8
Python 3.8.6 (default, Mar  7 2022, 16:47:42) 
[GCC 8.3.0 20190222 (Loongson 8.3.0-27 vec)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lief 
>>> binary=lief.parse("/bin/ls")
>>> print(binary)
Achitecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Architecture UNDEFINED not implemented
Header
======
Magic:                           7f 45 4c 46 
Class:                           CLASS64
Endianness:                      LSB
Version:                         CURRENT
OS/ABI:                          SYSTEMV
ABI Version:                     0
Machine type:                    UNDEFINED
File type:                       DYNAMIC
Object file version:             CURRENT
Entry Point:                     0x5d98
Program header offset:           0x40
Section header offset:           153312
Processor Flag:                  3 
Header size:                     64
Size of program header:          56
Number of program header:        9
Size of section header:          64
Number of section headers:       28
Section Name Table idx:          27

Sections
========
                    NULL           0         0         0         0                                                      
.interp             PROGBITS       238       f         238       3.50689   ALLOC 

修改后输出:

[loongson@localhost dist]$ python3.8
Python 3.8.6 (default, Mar  7 2022, 16:47:42) 
[GCC 8.3.0 20190222 (Loongson 8.3.0-27 vec)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lief
>>> binary=lief.parse("/bin/ls")
>>> print(binary)
Header
======
Magic:                           7f 45 4c 46 
Class:                           CLASS64
Endianness:                      LSB
Version:                         CURRENT
OS/ABI:                          SYSTEMV
ABI Version:                     0
Machine type:                    LOONGARCH
File type:                       DYNAMIC
Object file version:             CURRENT
Entry Point:                     0x5d98
Program header offset:           0x40
Section header offset:           153312
Processor Flag:                  3 BASE_ABI_LP64S BASE_ABI_LP64F BASE_ABI BASE_ABI_ILP32S BASE_ABI_ILP32F BASE_ABI_ILP32D
Header size:                     64
Size of program header:          56
Number of program header:        9
Size of section header:          64
Number of section headers:       28
Section Name Table idx:          27

Sections
========
                    NULL           0         0         0         0        

.interp             PROGBITS       238       f         238       3.50689   ALLOC                         INTERP LOAD    
.note.ABI-tag       NOTE           248       20        248       1.49878   ALLOC                         LOAD NOTE        

include/LIEF/ELF/enums.hpp Outdated Show resolved Hide resolved
include/LIEF/ELF/enums.hpp Outdated Show resolved Hide resolved
include/LIEF/ELF/enums.hpp Outdated Show resolved Hide resolved
include/LIEF/ELF/enums.inc Outdated Show resolved Hide resolved
include/LIEF/ELF/enums.inc Outdated Show resolved Hide resolved
include/LIEF/ELF/enums.inc Outdated Show resolved Hide resolved
src/ELF/EnumToString.cpp Outdated Show resolved Hide resolved
@yetist
Copy link

yetist commented Apr 6, 2023

这是直接把 32位干掉了吗?现在用的这个名字,看起来就是不会再给32位任何机会了啊

@loongson-zn
Copy link
Collaborator Author

这是直接把 32位干掉了吗?现在用的这个名字,看起来就是不会再给32位任何机会了啊

根据新的binutils 来写的

return false;
}

return (processor_flag() & static_cast<uint32_t>(f)) > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边看看能不能有机会正确处理 EF_LOONGARCH_OBJABI_V1:如果 f 是这玩意,则 mask 出位域做相等比较,否则像现在写法一样做 bitwise and 比较。

工程实践上,操作这个 flag 完全是合理需求,所以如果你要适配这个库,一定要支持它。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边看看能不能有机会正确处理 EF_LOONGARCH_OBJABI_V1:如果 f 是这玩意,则 mask 出位域做相等比较,否则像现在写法一样做 bitwise and 比较。

手头紧急工作告一段落,接着搞LIEF。 我咨询了一下相关的同事,上游支持的代码都是新世界的,不考虑旧世界,上游默认都是V1

@xry111
Copy link

xry111 commented Apr 7, 2023

这是直接把 32位干掉了吗?现在用的这个名字,看起来就是不会再给32位任何机会了啊

现在用 ELFCLASS32/ELFCLASS64 区分 32 位和 64 位。

@yetist
Copy link

yetist commented Apr 7, 2023

这是直接把 32位干掉了吗?现在用的这个名字,看起来就是不会再给32位任何机会了啊

现在用 ELFCLASS32/ELFCLASS64 区分 32 位和 64 位。

这样说就靠谱多了,名字也比原来看着舒服些。

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.

4 participants