File tree Expand file tree Collapse file tree 6 files changed +34
-2
lines changed Expand file tree Collapse file tree 6 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 2727 .int32 0
2828 .size foo, 4
2929
30+ .section .debug_info,"",@
31+ .p2align 2
32+ .int32 unused_function
33+ .int32 _start
34+ .int32 0
35+
3036# CHECK: - Type: CODE
3137# CHECK-NEXT: Relocations:
3238# CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB
4248# CHECK-NEXT: Value: 1024
4349# CHECK-NEXT: Content: '00000000'
4450
51+ # There should be a single relocation in this section (just the live symbol)
52+ # CHECK-NEXT: - Type: CUSTOM
53+ # CHECK-NEXT: Relocations:
54+ # CHECK-NEXT: - Type: R_WASM_FUNCTION_OFFSET_I32
55+ # CHECK-NEXT: Index: 0
56+ # CHECK-NEXT: Offset: 0x4
57+ # CHECK-NEXT: Name: .debug_info
58+ # CHECK-NEXT: Payload: FFFFFFFF0200000000000000
59+
4560# CHECK: - Type: CUSTOM
4661# CHECK-NEXT: Name: linking
4762# CHECK-NEXT: Version: 2
Original file line number Diff line number Diff line change @@ -167,6 +167,19 @@ void InputChunk::relocate(uint8_t *buf) const {
167167 }
168168}
169169
170+ static bool relocIsLive (const WasmRelocation& rel, ObjFile* file) {
171+ return rel.Type == R_WASM_TYPE_INDEX_LEB ||
172+ file->getSymbol (rel.Index )->isLive ();
173+ }
174+
175+ size_t InputChunk::getNumLiveRelocations () const {
176+ size_t result = 0 ;
177+ for (const WasmRelocation& rel : relocations) {
178+ if (relocIsLive (rel, file)) result ++;
179+ }
180+ return result;
181+ }
182+
170183// Copy relocation entries to a given output stream.
171184// This function is used only when a user passes "-r". For a regular link,
172185// we consume relocations instead of copying them to an output file.
@@ -179,6 +192,8 @@ void InputChunk::writeRelocations(raw_ostream &os) const {
179192 << " offset=" << Twine (off) << " \n " );
180193
181194 for (const WasmRelocation &rel : relocations) {
195+ if (!relocIsLive (rel, file))
196+ continue ;
182197 writeUleb128 (os, rel.Type , " reloc type" );
183198 writeUleb128 (os, rel.Offset + off, " reloc offset" );
184199 writeUleb128 (os, file->calcNewIndex (rel), " reloc index" );
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ class InputChunk {
7777 uint32_t getInputSectionOffset () const { return inputSectionOffset; }
7878
7979 size_t getNumRelocations () const { return relocations.size (); }
80+ size_t getNumLiveRelocations () const ;
8081 void writeRelocations (llvm::raw_ostream &os) const ;
8182 bool generateRelocationCode (raw_ostream &os) const ;
8283
Original file line number Diff line number Diff line change @@ -274,7 +274,7 @@ void CustomSection::writeTo(uint8_t *buf) {
274274uint32_t CustomSection::getNumRelocations () const {
275275 uint32_t count = 0 ;
276276 for (const InputChunk *inputSect : inputSections)
277- count += inputSect->getNumRelocations ();
277+ count += inputSect->getNumLiveRelocations ();
278278 return count;
279279}
280280
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ class OutputSection {
4141 virtual void writeTo (uint8_t *buf) = 0;
4242 virtual void finalizeContents () = 0;
4343 virtual uint32_t getNumRelocations () const { return 0 ; }
44+ virtual uint32_t getNumLiveRelocations () const { return getNumRelocations (); }
4445 virtual void writeRelocations (raw_ostream &os) const {}
4546
4647 std::string header;
Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ void Symbol::markLive() {
183183}
184184
185185uint32_t Symbol::getOutputSymbolIndex () const {
186- assert (outputSymbolIndex != INVALID_INDEX);
186+ assert (outputSymbolIndex != INVALID_INDEX || ! isLive () );
187187 return outputSymbolIndex;
188188}
189189
You can’t perform that action at this time.
0 commit comments