0

I have some attribute((used, section ... )) codes, so I need modify the main.lds file.

  1. run ld --verbose >> main.lds to generate the default main.lds file. It's 64 bits version, I need 32 bits version.

  2. modify main.lds

    OUTPUT_FORMAT(pei-i386) .bss BLOCK(section_alignment) : { *(.app_init.0) *(.app_init.1) *(.app_init.2) ....

  3. modify tasks.json file in vscode.

       "command": "gcc.exe",
       "args": [                         
           "-g",
           "-m32",
           "-fshort-enums",      
           "${workspaceFolder}\\*.c", 
           "'-Wl,-Tmain.lds'",         
           "'-Wl,-Map=${workspaceFolder}\\obj\\${workspaceRootFolderName}.map'",                                                                                                                        
           "-o", "${workspaceFolder}\\obj\\${workspaceRootFolderName}.exe",                
          ],
    
  4. then I get 32bits main.exe, but it cannot run:
    Thread 1 received signal SIGSEGV, Segmentation fault. 0xffffffff in ?? ()

Did I miss something in the main.lds file?

( 1. if I don't modify main.lds and delete "-m32" in tasks.json, I can get 64bit main.exe and it run correctly. and my sections code also run correctly. 2. if I delete "'-Wl,-Tmain.lds'" in tasks.json, I can get 32bit main.exe with default lds file and it run correctly. but my sections code don't run correctly. )

need help. thank you very much.

qinxg
  • 1

1 Answers1

0

I had resolved this problem. gcc -m32 main.c '-Wl,--verbose' can output 32 bits version lds file contents. this lds file is correct!

qinxg
  • 1