Arch Arm的交叉编译不会生成功能性可执行文件

Arch Arm的交叉编译不会生成功能性可执行文件,c,cross-compiling,raspberry-pi3,archlinux,archlinux-arm,C,Cross Compiling,Raspberry Pi3,Archlinux,Archlinux Arm,我安装到Rpi3上,然后将sysroot同步到安装在联想thinkpad上的x86_64 Arch Linux上 然后我安装了Linaro交叉编译器 为了避免任何问题,我在编译中使用了绝对路径: /home/sameh/Rpi/Compiler/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc\ --sysroot=/home/sameh/Rpi/Arch/ArmV7/root\ -

我安装到Rpi3上,然后将sysroot同步到安装在联想thinkpad上的x86_64 Arch Linux上

然后我安装了Linaro交叉编译器

为了避免任何问题,我在编译中使用了绝对路径:

/home/sameh/Rpi/Compiler/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc\
 --sysroot=/home/sameh/Rpi/Arch/ArmV7/root\
 -o stress stress.c -lm
代码编译得很好,但是当我在Rpi3上执行它时,它没有输出

它不会释放Pi,我可以查看由
fork()
创建的子进程

但是没有任何调试语句被打印,也没有任何进程退出

编辑

此代码基于库。对于MCVE,我将其最小化为仅使用
hogcpu
函数

#include <ctype.h>
#include <errno.h>
#include <libgen.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <sys/wait.h>

int hogcpu (void);

int
hogcpu (void)
{
  for(int i=0; i < 1000000; i++)
    sqrt (rand ());
  return 0;
}

int main()
{

  struct timespec start, end;
  double cpu_time_used;
  int pid, children = 0, retval = 0;
  long forks;
  int do_dryrun = 0;
  long long do_backoff = 3000;

  long long do_cpu = 1;
  long long backoff, timeout = 0;

  /* Calculate the backoff value so we get good fork throughput.  */
  backoff = do_backoff * forks;

  clock_gettime(CLOCK_REALTIME, &start); 

  while ((forks = (do_cpu + do_io + do_vm + do_hdd)))
  {
    if (do_cpu)
    {
      switch (pid = fork ())
        {
        case 0:            /* child */
          alarm (timeout);
          usleep (backoff);
          exit (hogcpu ());
        case -1:           /* error */
          break;
        default:
          ++children;
        }
      --do_cpu;
    }

  }
  /* Wait for our children to exit.  */
  while (children)
  {
    int status, ret;

    if ((pid = wait (&status)) > 0)
    {
      --children;
      if (WIFEXITED (status))
      {
        if ((ret = WEXITSTATUS (status)) == 0)
        {
          printf( "<-- worker %i returned normally\n", pid);
        }
        else
        {
          printf( "<-- worker %i returned error %i\n", pid, ret);
          ++retval;
          printf( "now reaping child worker processes\n");
          if (signal (SIGUSR1, SIG_IGN) == SIG_ERR)
            printf( "handler error: %s\n", strerror (errno));
          if (kill (-1 * getpid (), SIGUSR1) == -1)
            printf( "kill error: %s\n", strerror (errno));
        }
      }
    }
  }

  clock_gettime(CLOCK_REALTIME, &end); 
  cpu_time_used = (end.tv_nsec = start.tv_nsec) / 1000000000.0;
  /* Print final status message.  */
  if (retval)
  {
    printf( "failed run completed in %.2f s\n", cpu_time_used);
  }
  else
  {
    printf( "successful run completed in -- %.2f s\n", cpu_time_used);
  }

  exit (retval);
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
int hogcpu(无效);
int
hogcpu(无效)
{
对于(int i=0;i<1000000;i++)
sqrt(兰特());
返回0;
}
int main()
{
结构timespec开始、结束;
使用双cpu时间;
int-pid,children=0,retval=0;
长叉;
int do_dryrun=0;
长时间退避=3000;
长do_cpu=1;
长退避,超时=0;
/*计算退避值,以便获得良好的fork吞吐量*/
退避=退避*叉子;
时钟获取时间(时钟实时和启动);
而((forks=(do_cpu+do_io+do_vm+do_hdd)))
{
如果(不使用cpu)
{
开关(pid=fork())
{
案例0:/*儿童*/
报警(超时);
usleep(退避);
退出(hogcup());
案例-1:/*错误*/
打破
违约:
++儿童;
}
--不使用cpu;
}
}
/*等待我们的孩子离开*/
(儿童)
{
int状态,ret;
如果((pid=等待(&status))>0)
{
--儿童;
如果(妻子退出(状态))
{
如果((ret=WEXITSTATUS(状态))==0)
{

printf(“这里的问题是
long forks;
变量是如何初始化的。我对编译器不太熟悉,但是因为
forks
没有初始化,所以计算
backoff=do_backoff*forks;
导致了一个随机负数

这阻止了调用
usleep(backoff);
完成。因此将
forks
初始化为1修复了该问题


我本以为
forks
应该被编译器初始化为
0
,作为
bss\U数据的过去,所以我不知道为什么它没有。可能需要对该部分进行更多的研究,但代码现在通过交叉编译执行得很好。

你能把它简化为MCVE吗?当然,现在就试试看。”我本以为
forks
应该被编译器初始化为0,作为
bss\u数据的过去,所以我不知道为什么它没有初始化“
forks
是一个局部变量,如果您不初始化它,它将得到堆栈/寄存器上发生的任何东西;更抽象地说,C标准说,从未初始化的变量读取是未定义的行为。
.bss
用于全局变量(更准确地说:用于静态存储持续时间变量,即全局变量+
static
locals,它们是伪装的全局变量),如果未显式初始化,则保证为0。顺便说一句,使用
-Wall-Wextra-O3
编译时会立即发现这一点。您应该养成在编译时启用大多数警告以避免这些陷阱的习惯。很好!感谢您的提示!例如。顺便说一句,在原始代码
中ode>do_vm
do_hdd
缺失。
[alarm@control ~]$ gcc stress.c -o stress -lm
[alarm@control ~]$ ./stress 
<-- worker 16834 returned normally
<-- worker 16835 returned normally
<-- worker 16836 returned normally
successful run completed in -- 0.90 s