Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
¿Por qué nmagic hace que mi aplicación se bloquee cuando uso vars globales?

Noté (lamentablemente de la manera más difícil) que -Wl,--nmagic también conocida como la opción del enlazador -n , hace que mi aplicación falle cuando uso variables globales. Leer la página del manual realmente no responde por qué. Lo estaba usando porque trajo mi binario de 14K a 1K (y menos de 1K si uso algunos comandos más). ¿Hay algo que pueda hacer para restaurar el comportamiento adecuado? Enhebreo un hilo local pero no puedo averiguar cómo configurar la memoria local del hilo. los compiladores de c dicen que FS no es un registro válido y mov fs, rax crea una instrucción no válida (o algo así)

Cosas que noté:

  • Si no asigno un valor, funciona (es por eso que tengo la declaración if).
  • Si lo hago const int test=6 funciona (tendrás que borrar el if)
  • Sin la opción nmagic funciona sin cambios

Fuente:

 //clang or gcc -static -Wl,--nmagic -nostdlib test.c typedef unsigned long long int size_t; typedef long long int ssize_t; typedef long long int int64_t; ssize_t my_write(int fd, const void *buf, size_t size) { register int64_t rax __asm__ ("rax") = 1; register int rdi __asm__ ("rdi") = fd; register const void *rsi __asm__ ("rsi") = buf; register size_t rdx __asm__ ("rdx") = size; __asm__ __volatile__ ( "syscall" : "+r" (rax) : "r" (rdi), "r" (rsi), "r" (rdx) : "cc", "rcx", "r11", "memory" ); return rax; } void my_exit(int exit_status) { register int64_t rax __asm__ ("rax") = 60; register int rdi __asm__ ("rdi") = exit_status; __asm__ __volatile__ ( "syscall" : "+r" (rax) : "r" (rdi) : "cc", "rcx", "r11", "memory" ); } int test=6; //if this isn't assigned it works fine int _start(){ if (test == 0) test=6; my_write(1, "Hello\n", test); my_exit(0); return 0; }

tamaño -A ./a.fuera

 section size addr .note.gnu.property 48 4194816 .note.gnu.build-id 36 4194864 .text 127 4198400 .rodata 7 4202496 .eh_frame 120 4202504 .data 4 4210688 .comment 18 0 Total 360
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!