@@ -2593,6 +2593,50 @@ ObjectFileELF::ParseTrampolineSymbols(Symtab *symbol_table, user_id_t start_id,
2593
2593
rel_data, symtab_data, strtab_data);
2594
2594
}
2595
2595
2596
+ static void ApplyELF64ABS64Relocation (Symtab *symtab, ELFRelocation &rel,
2597
+ DataExtractor &debug_data,
2598
+ Section *rel_section) {
2599
+ Symbol *symbol = symtab->FindSymbolByID (ELFRelocation::RelocSymbol64 (rel));
2600
+ if (symbol) {
2601
+ addr_t value = symbol->GetAddressRef ().GetFileAddress ();
2602
+ DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer ();
2603
+ // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
2604
+ WritableDataBuffer *data_buffer =
2605
+ llvm::cast<WritableDataBuffer>(data_buffer_sp.get ());
2606
+ uint64_t *dst = reinterpret_cast <uint64_t *>(
2607
+ data_buffer->GetBytes () + rel_section->GetFileOffset () +
2608
+ ELFRelocation::RelocOffset64 (rel));
2609
+ uint64_t val_offset = value + ELFRelocation::RelocAddend64 (rel);
2610
+ memcpy (dst, &val_offset, sizeof (uint64_t ));
2611
+ }
2612
+ }
2613
+
2614
+ static void ApplyELF64ABS32Relocation (Symtab *symtab, ELFRelocation &rel,
2615
+ DataExtractor &debug_data,
2616
+ Section *rel_section, bool is_signed) {
2617
+ Symbol *symbol = symtab->FindSymbolByID (ELFRelocation::RelocSymbol64 (rel));
2618
+ if (symbol) {
2619
+ addr_t value = symbol->GetAddressRef ().GetFileAddress ();
2620
+ value += ELFRelocation::RelocAddend32 (rel);
2621
+ if ((!is_signed && (value > UINT32_MAX)) ||
2622
+ (is_signed &&
2623
+ ((int64_t )value > INT32_MAX || (int64_t )value < INT32_MIN))) {
2624
+ Log *log = GetLog (LLDBLog::Modules);
2625
+ LLDB_LOGF (log, " Failed to apply debug info relocations" );
2626
+ return ;
2627
+ }
2628
+ uint32_t truncated_addr = (value & 0xFFFFFFFF );
2629
+ DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer ();
2630
+ // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
2631
+ WritableDataBuffer *data_buffer =
2632
+ llvm::cast<WritableDataBuffer>(data_buffer_sp.get ());
2633
+ uint32_t *dst = reinterpret_cast <uint32_t *>(
2634
+ data_buffer->GetBytes () + rel_section->GetFileOffset () +
2635
+ ELFRelocation::RelocOffset32 (rel));
2636
+ memcpy (dst, &truncated_addr, sizeof (uint32_t ));
2637
+ }
2638
+ }
2639
+
2596
2640
unsigned ObjectFileELF::ApplyRelocations (
2597
2641
Symtab *symtab, const ELFHeader *hdr, const ELFSectionHeader *rel_hdr,
2598
2642
const ELFSectionHeader *symtab_hdr, const ELFSectionHeader *debug_hdr,
@@ -2656,55 +2700,50 @@ unsigned ObjectFileELF::ApplyRelocations(
2656
2700
reloc_type (rel));
2657
2701
}
2658
2702
} else {
2659
- switch (reloc_type (rel)) {
2660
- case R_AARCH64_ABS64:
2661
- case R_X86_64_64: {
2662
- symbol = symtab->FindSymbolByID (reloc_symbol (rel));
2663
- if (symbol) {
2664
- addr_t value = symbol->GetAddressRef ().GetFileAddress ();
2665
- DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer ();
2666
- // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
2667
- WritableDataBuffer *data_buffer =
2668
- llvm::cast<WritableDataBuffer>(data_buffer_sp.get ());
2669
- uint64_t *dst = reinterpret_cast <uint64_t *>(
2670
- data_buffer->GetBytes () + rel_section->GetFileOffset () +
2671
- ELFRelocation::RelocOffset64 (rel));
2672
- uint64_t val_offset = value + ELFRelocation::RelocAddend64 (rel);
2673
- memcpy (dst, &val_offset, sizeof (uint64_t ));
2703
+ switch (hdr->e_machine ) {
2704
+ case llvm::ELF::EM_AARCH64:
2705
+ switch (reloc_type (rel)) {
2706
+ case R_AARCH64_ABS64:
2707
+ ApplyELF64ABS64Relocation (symtab, rel, debug_data, rel_section);
2708
+ break ;
2709
+ case R_AARCH64_ABS32:
2710
+ ApplyELF64ABS32Relocation (symtab, rel, debug_data, rel_section, true );
2711
+ break ;
2712
+ default :
2713
+ assert (false && " unexpected relocation type" );
2674
2714
}
2675
2715
break ;
2676
- }
2677
- case R_X86_64_32:
2678
- case R_X86_64_32S:
2679
- case R_AARCH64_ABS32: {
2680
- symbol = symtab->FindSymbolByID (reloc_symbol (rel));
2681
- if (symbol) {
2682
- addr_t value = symbol->GetAddressRef ().GetFileAddress ();
2683
- value += ELFRelocation::RelocAddend32 (rel);
2684
- if ((reloc_type (rel) == R_X86_64_32 && (value > UINT32_MAX)) ||
2685
- (reloc_type (rel) == R_X86_64_32S &&
2686
- ((int64_t )value > INT32_MAX && (int64_t )value < INT32_MIN)) ||
2687
- (reloc_type (rel) == R_AARCH64_ABS32 &&
2688
- ((int64_t )value > INT32_MAX && (int64_t )value < INT32_MIN))) {
2689
- Log *log = GetLog (LLDBLog::Modules);
2690
- LLDB_LOGF (log, " Failed to apply debug info relocations" );
2691
- break ;
2692
- }
2693
- uint32_t truncated_addr = (value & 0xFFFFFFFF );
2694
- DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer ();
2695
- // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
2696
- WritableDataBuffer *data_buffer =
2697
- llvm::cast<WritableDataBuffer>(data_buffer_sp.get ());
2698
- uint32_t *dst = reinterpret_cast <uint32_t *>(
2699
- data_buffer->GetBytes () + rel_section->GetFileOffset () +
2700
- ELFRelocation::RelocOffset32 (rel));
2701
- memcpy (dst, &truncated_addr, sizeof (uint32_t ));
2716
+ case llvm::ELF::EM_LOONGARCH:
2717
+ switch (reloc_type (rel)) {
2718
+ case R_LARCH_64:
2719
+ ApplyELF64ABS64Relocation (symtab, rel, debug_data, rel_section);
2720
+ break ;
2721
+ case R_LARCH_32:
2722
+ ApplyELF64ABS32Relocation (symtab, rel, debug_data, rel_section, true );
2723
+ break ;
2724
+ default :
2725
+ assert (false && " unexpected relocation type" );
2726
+ }
2727
+ break ;
2728
+ case llvm::ELF::EM_X86_64:
2729
+ switch (reloc_type (rel)) {
2730
+ case R_X86_64_64:
2731
+ ApplyELF64ABS64Relocation (symtab, rel, debug_data, rel_section);
2732
+ break ;
2733
+ case R_X86_64_32:
2734
+ ApplyELF64ABS32Relocation (symtab, rel, debug_data, rel_section,
2735
+ false );
2736
+ break ;
2737
+ case R_X86_64_32S:
2738
+ ApplyELF64ABS32Relocation (symtab, rel, debug_data, rel_section, true );
2739
+ break ;
2740
+ case R_X86_64_PC32:
2741
+ default :
2742
+ assert (false && " unexpected relocation type" );
2702
2743
}
2703
2744
break ;
2704
- }
2705
- case R_X86_64_PC32:
2706
2745
default :
2707
- assert (false && " unexpected relocation type " );
2746
+ assert (false && " unsupported machine " );
2708
2747
}
2709
2748
}
2710
2749
}
0 commit comments