error due to section overlap in linker script

65 Views Asked by At

I am trying to compile a c program for baremetal riscv core. What I am trying to do is generate random values put them in a dynamic array and send them through ROCC instructions.

Here is the c program:

#define _GNU_SOURCE

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdint.h>
#include <math.h>

#include <inttypes.h>
#include <time.h>

#include "rocc.h"
#include "encoding.h"

int64_t test_value = 0x000001FF37F3DF3F83FD;

uint64_t generateRandomValue();
void generateValues(int numValues, uint64_t** values);

void freeMemory(int64_t* array) {
    free(array);              }
uint64_t concatenate_ints(int x, int y);
uint64_t concatenate_arrays(int64_t* x, int64_t* y);
uint64_t* concatenateArrays(const uint64_t* x, size_t sizeX, const uint64_t* y, size_t sizeY);

int main() {
    srand((unsigned int)time(NULL));
    
    int numTests  = 16;
    int numData1;
    int numData2;
    uint64_t last_flag;
    printf("Enter the number of random Data1 to generate: ");
    scanf("%d", &numData1);
    printf("Enter the number of random Data2 to generate: ");
    scanf("%d", &numData2);

    uint64_t* generatedData1 = NULL;
    uint64_t* generatedData2 = NULL;
    uint64_t* data1_data2      = NULL;

    generateValues(numData1, &generatedData1);
    generateValues(numData1, &generatedData1);

    data1_data2 = concatenateArrays(generatedData1, numData1, generatedData2, numData2);
    uint64_t data1_data2_packets = concatenate_ints(numData2, numData1);
    uint64_t data1_data2_bits   = concatenate_ints(numData2 * 64, numData1 * 64);

    __asm__ volatile ("fence");
    //Data1, Data2 and test_value
     ROCC_INSTRUCTION_SS(0, data1_data2, test_value, 0);
    __asm__ volatile("fence":::"memory");

    //size of input arrays
    __asm__ volatile ("fence");
     ROCC_INSTRUCTION_DSS(0, last_flag, data1_data2_bits, data1_data2_packets, 1);
    __asm__ volatile("fence":::"memory");
   
    printf("wating for the last flag");
    uint64_t* NextData = NULL;

    do{
      if(last_round)
      {
        srand((unsigned int)time(NULL));
        generateValues(numData1, &NextData);
        //size of input arrays
        __asm__ volatile ("fence");
        ROCC_INSTRUCTION_DS(0, last_flag, NextData, 2);
        __asm__ volatile("fence":::"memory");
        // Freeing allocated memory
        freeMemory(NextData);

      }
    }while(numTests--);
    

    /*
    // Printing generated values
    printf("Generated Values:\n");
    for (int i = 0; i < numData1; ++i) {
        printf("0x%016" PRIx64 "\n", generatedData1[i]);
    }
*/
    
 
    // Freeing allocated memory
    freeMemory(generatedData1);
    // Freeing allocated memory
    freeMemory(generatedData2);
    return 0;
}
    uint64_t generateRandomValue() {
    return  ((uint64_t)rand() << 32) | rand();
}
void generateValues(int numValues, uint64_t** values) {
    *values = (uint64_t*)malloc(numValues * sizeof(uint64_t));

    for (int i = 0; i < numValues; ++i) {
        (*values)[i] = generateRandomValue();
    }
}

uint64_t concatenate_ints(int x, int y) {
    return ((uint64_t)x << 32) | y;        
}
uint64_t concatenate_arrays(int64_t* x, int64_t* y) {
    return ((uint64_t)x << 32) | (uint64_t)y;
}

uint64_t* concatenateArrays(const uint64_t* x, size_t sizeX, const uint64_t* y, size_t sizeY) {
    // Allocate memory for the resulting array
    uint64_t* result = (uint64_t*)malloc((sizeX + sizeY) * sizeof(uint64_t));
    
    // Copy elements from the first array (x) to the result array
    for (size_t i = 0; i < sizeX; ++i) {
        result[i] = x[i];
    }

    // Copy elements from the second array (y) to the result array
    for (size_t i = 0; i < sizeY; ++i) {
        result[sizeX + i] = y[i];
    }

    return result;
}

And here is the linker script:

OUTPUT_ARCH( "riscv" )
ENTRY(_start)

/*----------------------------------------------------------------------*/
/* Sections                                                             */
/*----------------------------------------------------------------------*/

SECTIONS
{
  /* Set the initial address for the text section */
  . = 0x80000000;

  /* .text.init section for initialization code */
  .text.init : { *(.text.init) }

  /* .tohost section for communication with the host */
  .tohost ALIGN(0x1000) : { *(.tohost) }

  /* Separate .text section to avoid overlap with .rodata */
  .text : {
    *(.text)
  }

  /* Set the address for the .rodata section */
  . = 0x80004000;

  /* .rodata section for read-only data */
  .rodata : {
    *(.rodata)
  }

  /* Set the address for the data section */
  . = ALIGN(0x40);
  .data : {
    *(.data)
  }

  /* .sdata section for initialized small data */
  .sdata : {
    __global_pointer$ = . + 0x800;
    *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata*)
    *(.sdata .sdata.* .gnu.linkonce.s.*)
  }

  /* .sbss section for uninitialized small data */
  .sbss : {
    *(.sbss .sbss.* .gnu.linkonce.sb.*)
    *(.scommon)
  }

  /* Set the address for the bss section */
  .bss ALIGN(0x40) : {
    *(.bss)
  }

  /* .tdata section for thread-local initialized data */
  .tdata : {
    _tls_data = .;
    *(.tdata.begin)
    *(.tdata)
    *(.tdata.end)
  }

  /* .tbss section for thread-local uninitialized data */
  .tbss : {
    *(.tbss)
    *(.tbss.end)
  }

  /* End of uninitialized data segment */
  _end = .;
}

When I try to compile and generate the binary for riscv, I get the following errors (could you please tell me how to get rid of these messages):

riscv64-unknown-elf-gcc -DPREALLOCATE=1 -mcmodel=medany -static -std=gnu99 -O2 -ffast-math -fno-common -fno-builtin-printf -fno-tree-loop-distribute-patterns -o test.riscv test.c syscalls.c crt.S -static -nostdlib -nostartfiles -ffreestanding -W -lm -lgcc -lc -lgloss -lc -T link.ld
riscv64-unknown-elf-gcc: section .rodata LMA [0000000080004000,0000000080004157] overlaps section .text.__svfscanf_r LMA [0000000080001fdc,00000000800043e5]
riscv64-unknown-elf-gcc: section .text.vfscanf LMA [00000000800043e6,0000000080004429] overlaps section .rodata.__svfscanf_r LMA [000000008000424c,0000000080004617]
riscv64-unknown-elf-gcc: section .rodata.basefix.0 LMA [0000000080004618,0000000080004639] overlaps section .text.__sfp LMA [00000000800045f2,00000000800046c1]
riscv64-unknown-elf-gcc: section .text._cleanup LMA [00000000800046c2,00000000800046d1] overlaps section .rodata._ctype_ LMA [0000000080004640,0000000080004740]
riscv64-unknown-elf-gcc: section .rodata._setlocale_r.str1.8 LMA [0000000080004748,0000000080004758] overlaps section .text._fread_r LMA [00000000800046fe,000000008000487b]
riscv64-unknown-elf-gcc: section .text.fread LMA [000000008000487c,0000000080004889] overlaps section .rodata.fpi.1 LMA [0000000080004870,0000000080004883]
riscv64-unknown-elf-gcc: section .rodata.tinytens LMA [0000000080004888,00000000800048af] overlaps section .text.fread LMA [000000008000487c,0000000080004889]
riscv64-unknown-elf-gcc: section .text._malloc_trim_r LMA [000000008000488a,0000000080004955] overlaps section .rodata.tinytens LMA [0000000080004888,00000000800048af]
riscv64-unknown-elf-gcc: section .rodata.ULtox LMA [00000000800048b0,00000000800048cb] overlaps section .text._malloc_trim_r LMA [000000008000488a,0000000080004955]
riscv64-unknown-elf-gcc: section .text._free_r LMA [0000000080004956,0000000080004ba3] overlaps section .rodata.__gethex.str1.8 LMA [00000000800048e0,0000000080004987]
riscv64-unknown-elf-gcc: section .rodata.__hexdig LMA [0000000080004988,0000000080004a87] overlaps section .text._free_r LMA [0000000080004956,0000000080004ba3]
riscv64-unknown-elf-gcc: section .text._fwalk LMA [0000000080004ba4,0000000080004c1f] overlaps section .rodata.__mprec_bigtens LMA [0000000080004b80,0000000080004ba7]
riscv64-unknown-elf-gcc: section .rodata.__mprec_tens LMA [0000000080004ba8,0000000080004c6f] overlaps section .text._fwalk LMA [0000000080004ba4,0000000080004c1f]
riscv64-unknown-elf-gcc: section .text._fwalk_reent LMA [0000000080004c20,0000000080004ca3] overlaps section .rodata.__mprec_tens LMA [0000000080004ba8,0000000080004c6f]
riscv64-unknown-elf-gcc: section .rodata.increment.str1.8 LMA [0000000080004c70,0000000080004d12] overlaps section .text._fwalk_reent LMA [0000000080004c20,0000000080004ca3]
riscv64-unknown-elf-gcc: section .text._gettimeofday_r LMA [0000000080004ca4,0000000080004cd7] overlaps section .rodata.increment.str1.8 LMA [0000000080004c70,0000000080004d12]
riscv64-unknown-elf-gcc: section .rodata._strtodg_l.str1.8 LMA [0000000080004d18,0000000080004d2a] overlaps section .text._setlocale_r LMA [0000000080004cf8,0000000080004d4f]
riscv64-unknown-elf-gcc: section .text.__locale_mb_cur_max LMA [0000000080004d50,0000000080004d59] overlaps section .rodata._strtodg_l LMA [0000000080004d2c,0000000080004de3]
riscv64-unknown-elf-gcc: section .rodata.fivesbits LMA [0000000080004de8,0000000080004e43] overlaps section .text._mbrtowc_r LMA [0000000080004db2,0000000080004e01]
riscv64-unknown-elf-gcc: section .text.mbrtowc LMA [0000000080004e02,0000000080004e5f] overlaps section .rodata.fivesbits LMA [0000000080004de8,0000000080004e43]
riscv64-unknown-elf-gcc: section .rodata.__assert_func.str1.8 LMA [0000000080004e48,0000000080004e8e] overlaps section .text.mbrtowc LMA [0000000080004e02,0000000080004e5f]
riscv64-unknown-elf-gcc: section .text._mbtowc_r LMA [0000000080004e60,0000000080004e69] overlaps section .rodata.__assert_func.str1.8 LMA [0000000080004e48,0000000080004e8e]
riscv64-unknown-elf-gcc: section .rodata._vfiprintf_r.str1.8 LMA [0000000080004e90,0000000080004ec6] overlaps section .text.__ascii_mbtowc LMA [0000000080004e6a,0000000080004ea9]
0

There are 0 best solutions below