Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7075855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:13:40+00:00 2026-05-28T06:13:40+00:00

I am trying to use a thread local variable in inline assembly, but when

  • 0

I am trying to use a thread local variable in inline assembly, but when I see the diassembled code, It appears that the compiler doesn’t generate the right code. For the following inline code, where saved_sp is globally declared as __thread long saved_sp,

__asm__ __volatile__ (
        "movq %rsp, saved_sp\n\t");

The disassembly looks like the following.

mov    %rsp,0x612008

Which is clearly not the right thing, because I know that gcc uses the fs segment for thread local variables. It should had generated something like

mov %rsp, fs:somevalue

which it is not. Why is that so? Is using thread local variables in inline assembly problematic?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:13:41+00:00Added an answer on May 28, 2026 at 6:13 am

    A simple thing that would surely work is to take a pointer to the thread local variable, and write to it.
    Your compiler will surely do long *saved_fp_p = &saved_fp correctly, and inline assembly will only deal with saved_fp_p, which is a local variable.

    You can also use gcc’s input and output syntax:

    __asm__ __volatile__ (
        "mov %%rsp, 0(%0)" : : "r" (&saved_sp)
    );
    

    This puts the compiler in charge of resolving the address of saved_fp, and the assembly code gets it in a register.

    We found out that this also works,

    __asm__ __volatile__ asm ("mov %rsp,%0" : "=m" (saved_sp))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use ThreadLocal to provide thread safety to pre-existing non-thread-safe classes, but
I'm trying to use a Thread in a simple winform. I have a ListBox
Trying to use a guid as a resource id in a rest url but
I am trying to learn how to use the C++ Boost.Thread library. I have
Trying to use log4j's built-in JMSAppender to log messages to a local message queue
I'm trying to use IIS 7 management API but stuck with a security issue.
I'm trying to accomplish the following: Have a thread that reads data from a
I am trying to use threads in a Python project I am working on,
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.