[PATCH] D127581: [ELF] Relax R_RISCV_ALIGN

Kito Cheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 04:40:54 PDT 2022


kito-cheng added inline comments.


================
Comment at: lld/ELF/Arch/RISCV.cpp:610
+      // Tell assignAddresses that the size has changed.
+      sec->bytesDropped = delta;
+    }
----------------
I hit overflow here as @gkm concern, and the fixed by changing `bytesDropped` to `uint16_t` (yeah, I tested the uint8_t version), maybe we can put an `assert (delta <= numeric_limits<uint16_t>::max());` here to make sure this could catch earlier?

I saw there are assertions for `byteDropped` in other place, so I think that should be reasonable?
```
[kitoc at xxxx llvm-project]$ grpe bytesDropped  * -R
...
lld/ELF/InputSection.h:  uint8_t bytesDropped = 0;
lld/ELF/InputSection.h:    assert(bytesDropped + num < 256);
lld/ELF/InputSection.h:    bytesDropped += num;
lld/ELF/InputSection.h:    assert(bytesDropped >= num);
lld/ELF/InputSection.h:    bytesDropped -= num;
...
```

Gonna run second round of testing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127581/new/

https://reviews.llvm.org/D127581



More information about the llvm-commits mailing list