AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1085183
Accepted
SDIdo
SDIdo
Asked: 2018-10-20 01:34:16 +0800 CST2018-10-20 01:34:16 +0800 CST 2018-10-20 01:34:16 +0800 CST

gcc -Hello.s 问题

  • 772

我的系统是 Ubuntu 18.04 64bit 。 安装了 build-essentials 和 devtools。

你好,我有一个名为 Hello.s 的程序集文件,内容如下:

        #This is a simple "Hello World!" program
    .section    .rodata #read only data section
str:    .string "Hello World!\n"
    ########
    .text   #the beginnig of the code
.globl  main    #the label "main" is used to state the initial point of this program
    .type   main, @function # the label "main" representing the beginning of a function
main:   # the main function:
    pushq   %rbp        #save the old frame pointer
    movq    %rsp,   %rbp    #create the new frame pointer

    movq    $str,%rdi   #the string is the only paramter passed to the printf function (remember- first parameter goes in %rdi).
    movq    $0,%rax
    call    printf      #calling to printf AFTER we passed its parameters.

    #return from printf:
    movq    $0, %rax    #return value is zero (just like in c - we tell the OS that this program finished seccessfully)
    movq    %rbp, %rsp  #restore the old stack pointer - release all used memory.
    popq    %rbp        #restore old frame pointer (the caller function frame)
    ret         #return to caller function (OS)

尝试使用 gcc -Hello.s 编译它会返回以下消息:

/usr/bin/ld: /tmp/ccY9hdWi.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC

/usr/bin/ld:最终链接失败:输出 collect2 上的不可表示部分:错误:ld 返回 1 退出状态

尝试了没有效果的 gcc -fPIC Hello.s - 带来了相同的消息。

有人告诉我安装gcc-4.8,那没用

还建议安装以前版本的 ubuntu.. 在我看来,这是最后的手段。

有什么建议么?

compiling gcc 18.04 assembler
  • 1 1 个回答
  • 779 Views

1 个回答

  • Voted
  1. Best Answer
    SDIdo
    2018-10-20T01:55:37+08:002018-10-20T01:55:37+08:00

    对于任何有兴趣的人。(对于像我这样的新手来说不是那么简单:))实际上可以在编译器之间进行选择!所以:

    gcc-4.8 Hello.s
    

    是答案。

    • 1

相关问题

  • 我可以在不重新编译源代码的情况下重建包吗?

  • 如何在没有 sudo 权限的情况下构建应用程序?

  • 为 i7 处理器编译内核的最佳方法是什么?

  • 如何将具有依赖项的包上传到我的 PPA?

  • 如何让 .so 文件显示在包中?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve