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 R_RISCV_SET_ULEB128 and R_RISCV_SUB_ULEB128. #162

Closed
wants to merge 1 commit into from
Closed

Add R_RISCV_SET_ULEB128 and R_RISCV_SUB_ULEB128. #162

wants to merge 1 commit into from

Conversation

kuanlinchentw
Copy link

Sorry for re-createing the pull request, because I deleted my fork of the previous pull request (#124).

Since the number 58 is occupied by R_RISCV_IRELATIVE. So I update relocation numbers of R_RISCV_SET_ULEB128 and R_RISCV_SUB_ULEB128.

@kito-cheng
Copy link
Collaborator

Latest version of this patch:

https://sourceware.org/pipermail/binutils/2020-January/109672.html

There is two issue left in last PR:

  1. From @jim-wilson

The assumption that the uleb128 address size can only decrease with relaxation is true only if both addresses are in the same section. If we are subtracting a text section address from a data section address, then that value could increase due to alignment padding between sections/segments. So I think these relocs should only be allowed when the symbols are in the same section. I think the binutils patch should be fixed to enforce this.

@kuanlinchentw I am not family with binutils code especially for linker part, did you have handle this on your latest patch?

  1. From @MaskRay

Apologies for making a comment without reading all previous discussions. I am a bit concerned about a relocation type without a clear width. See http://sourceware.org/PR4029 for an example that oscillating .uleb128 caused a bug. I don't really read through Alan Modra's workaround but I think it is about overaligning the label immediately preceding Type Tables. It works before type tables are accessed by adding a negative offset to TTBase.

@MaskRay I think that issue is happens on assemble time, it seems like not related to linker time, and I think it's hard to describe that clear width, or maybe we could add note that and mention this should not shirk the size after relaxation?

@kuanlinchentw
Copy link
Author

The assumption that the uleb128 address size can only decrease with relaxation is true only if both addresses are in the same section. If we are subtracting a text section address from a data section address, then that value could increase due to alignment padding between sections/segments. So I think these relocs should only be allowed when the symbols are in the same section. I think the binutils patch should be fixed to enforce this.

A uleb128 subtraction expression is only allowed both addresses in the same section currently.

Apologies for making a comment without reading all previous discussions. I am a bit concerned about a relocation type without a clear width. See http://sourceware.org/PR4029 for an example that oscillating .uleb128 caused a bug. I don't really read through Alan Modra's workaround but I think it is about overaligning the label immediately preceding Type Tables. It works before type tables are accessed by adding a negative offset to TTBase.

The linker relaxation for uleb128 should not shrink even the value could be represented with shorter length, it should pad with 0x80 to keep the same length just as before the relaxation.

@kito-cheng
Copy link
Collaborator

The linker relaxation for uleb128 should not shrink even the value could be represented with shorter length, it should pad with 0x80 to keep the same length just as before the relaxation.

@kuanlinchentw could you write this down into the document?

https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md#code-relax

kito-cheng added a commit that referenced this pull request Jan 30, 2023
ULEB128 has used in DWARF and exception handling table, it used to
record value, or record the distance between two symbols.

The later one would be an issue for debug info and exception handling
table, since the symbol address might updated during, then the value
might incorrect after relaxation, some of those field has alternative
encoding type, but some new field defined in DWARF 5 ins't provide
alternative format other than ULEB128, e.g. DW_RLE_offset_pair,
DW_RLE_startx_length, DW_RLE_startx_endx and DW_RLE_start_length.

This PR basically same as #162, but updated to the trunk,
and also document ULEB128 should not shrink the size of the data,
since we never know the data used in where and does the length has
recorded in somewhere or not, so this would be most safe way.

binutils patch: https://sourceware.org/pipermail/binutils/2020-January/109672.html
kito-cheng added a commit that referenced this pull request Jan 31, 2023
…_SUB_ULEB128

ULEB128 has used in DWARF and exception handling table, it used to
record value, or record the distance between two symbols.

The later one would be an issue for debug info and exception handling
table, since the symbol address might updated during, then the value
might incorrect after relaxation, some of those field has alternative
encoding type, but some new field defined in DWARF 5 ins't provide
alternative format other than ULEB128, e.g. DW_RLE_offset_pair,
DW_RLE_startx_length, DW_RLE_startx_endx and DW_RLE_start_length.

This PR basically same as #162, but updated to the trunk,
and also document ULEB128 should not shrink the size of the data,
since we never know the data used in where and does the length has
recorded in somewhere or not, so this would be most safe way.

binutils patch: https://sourceware.org/pipermail/binutils/2020-January/109672.html
kito-cheng added a commit that referenced this pull request Feb 20, 2023
…_SUB_ULEB128

ULEB128 has used in DWARF and exception handling table, it used to
record value, or record the distance between two symbols.

The later one would be an issue for debug info and exception handling
table, since the symbol address might updated during, then the value
might incorrect after relaxation, some of those field has alternative
encoding type, but some new field defined in DWARF 5 ins't provide
alternative format other than ULEB128, e.g. DW_RLE_offset_pair,
DW_RLE_startx_length, DW_RLE_startx_endx and DW_RLE_start_length.

This PR basically same as #162, but updated to the trunk,
and also document ULEB128 should not shrink the size of the data,
since we never know the data used in where and does the length has
recorded in somewhere or not, so this would be most safe way.

binutils patch: https://sourceware.org/pipermail/binutils/2020-January/109672.html
kito-cheng added a commit that referenced this pull request Mar 29, 2023
…_SUB_ULEB128

ULEB128 has used in DWARF and exception handling table, it used to
record value, or record the distance between two symbols.

The later one would be an issue for debug info and exception handling
table, since the symbol address might updated during, then the value
might incorrect after relaxation, some of those field has alternative
encoding type, but some new field defined in DWARF 5 ins't provide
alternative format other than ULEB128, e.g. DW_RLE_offset_pair,
DW_RLE_startx_length, DW_RLE_startx_endx and DW_RLE_start_length.

This PR basically same as #162, but updated to the trunk,
and also document ULEB128 should not shrink the size of the data,
since we never know the data used in where and does the length has
recorded in somewhere or not, so this would be most safe way.

binutils patch: https://sourceware.org/pipermail/binutils/2020-January/109672.html
kito-cheng added a commit that referenced this pull request Mar 30, 2023
…_SUB_ULEB128

ULEB128 has used in DWARF and exception handling table, it used to
record value, or record the distance between two symbols.

The later one would be an issue for debug info and exception handling
table, since the symbol address might updated during, then the value
might incorrect after relaxation, some of those field has alternative
encoding type, but some new field defined in DWARF 5 ins't provide
alternative format other than ULEB128, e.g. DW_RLE_offset_pair,
DW_RLE_startx_length, DW_RLE_startx_endx and DW_RLE_start_length.

This PR basically same as #162, but updated to the trunk,
and also document ULEB128 should not shrink the size of the data,
since we never know the data used in where and does the length has
recorded in somewhere or not, so this would be most safe way.

binutils patch: https://sourceware.org/pipermail/binutils/2020-January/109672.html
kito-cheng added a commit that referenced this pull request Mar 30, 2023
…_SUB_ULEB128

ULEB128 has used in DWARF and exception handling table, it used to
record value, or record the distance between two symbols.

The later one would be an issue for debug info and exception handling
table, since the symbol address might updated during, then the value
might incorrect after relaxation, some of those field has alternative
encoding type, but some new field defined in DWARF 5 ins't provide
alternative format other than ULEB128, e.g. DW_RLE_offset_pair,
DW_RLE_startx_length, DW_RLE_startx_endx and DW_RLE_start_length.

This PR basically same as #162, but updated to the trunk,
and also document ULEB128 should not shrink the size of the data,
since we never know the data used in where and does the length has
recorded in somewhere or not, so this would be most safe way.

binutils patch: https://sourceware.org/pipermail/binutils/2020-January/109672.html
@kuanlinchentw kuanlinchentw closed this by deleting the head repository Jun 5, 2023
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.

2 participants