Skip to content

Initialize ir->branch_table->PC with safe value #462

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

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

ChinYikMing
Copy link
Collaborator

If the ra(return address) is 0x0, the
LOOKUP_OR_UPDATE_BRANCH_HISTORY_TABLE will bahave abnormally since calloc initialize ir->branch_table->PC[i] to 0x0. The 0x0 address might be not yet translated to a valid block, thus ir->branch_table->target[i] might be NULL, calling a NULL function pointer cause segmentation fault. It can be solved by initializing ir->branch_table->PC will other value than 0x0. Here, I choose unsigned integer of -1.

Close #461

@jserv jserv requested a review from qwe661234 June 17, 2024 12:53
@jserv jserv added this to the release-2024.1 milestone Jun 17, 2024
Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Benchmarks

Benchmark suite Current: b65d24c Previous: 1e4ef3c Ratio
Dhrystone 5 Average DMIPS over 10 runs 5 Average DMIPS over 10 runs 1
Coremark 0.004 Average iterations/sec over 10 runs 0.004 Average iterations/sec over 10 runs 1

This comment was automatically generated by workflow using github-action-benchmark.

If the ra(return address) is 0x0, the
LOOKUP_OR_UPDATE_BRANCH_HISTORY_TABLE will bahave abnormally since
calloc initializes ir->branch_table->PC[i] to 0x0. The address 0x0 might
be not yet translated to a valid block, thus ir->branch_table->target[i]
might be NULL, accessing a NULL pointer causes segmentation fault. It
can be solved by initializing ir->branch_table->PC with other value than
0x0. Here, I choose unsigned integer of -1.

Close sysprog21#461
@ChinYikMing ChinYikMing force-pushed the branch-history-tbl-init branch from 1e4ef3c to b65d24c Compare June 17, 2024 14:40
@jserv jserv merged commit 892bc37 into sysprog21:master Jun 18, 2024
8 checks passed
@ChinYikMing ChinYikMing deleted the branch-history-tbl-init branch June 18, 2024 11:14
vestata pushed a commit to vestata/rv32emu that referenced this pull request Jan 24, 2025
…init

Initialize ir->branch_table->PC with safe value
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.

A segmentation fault occurs when running a simple ELF file
3 participants